Moralis polygon speedy node's latest block is always a few blocks older than other providers

Ran the following code using web3 web3.eth.get_block('latest')['number'] in python with various node providers at the same time and the results are as follows.

Moralis always returned latest blocks that are a few blocks older than other providers. Anyone encountered the same issue?

How do you connect to the node? Http or websocket

On what chain are you testing?

HTTP and Polygon. Here are more code snippet. (Need to replace some of the provider url with your own private api key)

from web3 import Web3
from web3.middleware import geth_poa_middleware

provider_url1 = 'https://rpc-mainnet.matic.quiknode.pro'
provider_url2 = 'https://polygon-mainnet.infura.io/v3/[YOUR_OWN_API_KEY]'
provider_url3 = '[OWN_QUICKNODE_API_KEY_URL]'
provider_url4 = 'https://polygon-rpc.com'
provider_url5 = 'https://speedy-nodes-nyc.moralis.io/[YOUR_OWN_API_KEY]/polygon/mainnet'

w3_1 = Web3(Web3.HTTPProvider(provider_url1))
w3_2 = Web3(Web3.HTTPProvider(provider_url2))
w3_3 = Web3(Web3.HTTPProvider(provider_url3))
w3_4 = Web3(Web3.HTTPProvider(provider_url4))
w3_5 = Web3(Web3.HTTPProvider(provider_url5))

w3_1.middleware_onion.inject(geth_poa_middleware, layer=0)
w3_2.middleware_onion.inject(geth_poa_middleware, layer=0)
w3_3.middleware_onion.inject(geth_poa_middleware, layer=0)
w3_4.middleware_onion.inject(geth_poa_middleware, layer=0)
w3_5.middleware_onion.inject(geth_poa_middleware, layer=0)

print('rpc-mainnet', w3_1.eth.get_block('latest')['number'])
print('infura', w3_2.eth.get_block('latest')['number'])
print('quicknode', w3_3.eth.get_block('latest')['number'])
print('poly-rpc', w3_4.eth.get_block('latest')['number'])
print('moralis', w3_5.eth.get_block('latest')['number'])

Can you try with another chain too, like eth or bsc?

I tried with bsc chain. It is fine there, all providers returned the same block most of the time.

so this only happens in polygon… any fix?

I don’t know now, I’ll have to test it too

I tested now with this script:

from web3 import Web3
from web3.middleware import geth_poa_middleware

provider_url1 = 'https://rpc-mainnet.matic.quiknode.pro'
provider_url4 = 'https://polygon-rpc.com'
provider_url5 = 'https://speedy-nodes-nyc.moralis.io/4243/polygon/mainnet'

w3_1 = Web3(Web3.HTTPProvider(provider_url1))
w3_4 = Web3(Web3.HTTPProvider(provider_url4))
w3_5 = Web3(Web3.HTTPProvider(provider_url5))

w3_1.middleware_onion.inject(geth_poa_middleware, layer=0)
w3_4.middleware_onion.inject(geth_poa_middleware, layer=0)
w3_5.middleware_onion.inject(geth_poa_middleware, layer=0)

print('rpc-mainnet-quicknode', w3_1.eth.get_block('latest')['number'])
print('poly-rpc', w3_4.eth.get_block('latest')['number'])
print('moralis', w3_5.eth.get_block('latest')['number'])

print('rpc-mainnet-quicknode', w3_1.eth.get_block('latest')['number'])
print('poly-rpc', w3_4.eth.get_block('latest')['number'])
print('moralis', w3_5.eth.get_block('latest')['number'])


print('rpc-mainnet-quicknode', w3_1.eth.get_block('latest')['number'])
print('poly-rpc', w3_4.eth.get_block('latest')['number'])
print('moralis', w3_5.eth.get_block('latest')['number'])

and I got this output:

rpc-mainnet-quicknode 27165121
poly-rpc 27165121
moralis 27165121
rpc-mainnet-quicknode 27165121
poly-rpc 27165121
moralis 27165121
rpc-mainnet-quicknode 27165122
poly-rpc 27165121
moralis 27165122

sometimes I get different results, there are multiple nodes behind a load balancer and you can get one at random using http

i think it a stroke of luck now… :sweat_smile:

Yea, it is very inconsistent. Just tested 10 more times but getting quite a few old blocks.
I have been seeing old blocks for quite awhile (for weeks). Would suggest testing it again at a different time later.

rpc-mainnet 27165531
poly-rpc 27165531
moralis 27165529
 
rpc-mainnet 27165533
poly-rpc 27165533
moralis 27165531
 
rpc-mainnet 27165535
poly-rpc 27165535
moralis 27165533
 
rpc-mainnet 27165537
poly-rpc 27165537
moralis 27165533
 
rpc-mainnet 27165540
poly-rpc 27165539
moralis 27165540
 
rpc-mainnet 27165541
poly-rpc 27165541
moralis 27165537
 
rpc-mainnet 27165543
poly-rpc 27165543
moralis 27165539
 
rpc-mainnet 27165545
poly-rpc 27165546
moralis 27165543
 
rpc-mainnet 27165547
poly-rpc 27165547
moralis 27165546
 
rpc-mainnet 27165549
poly-rpc 27165550
moralis 27165546