I have a project with Node.js
version 13 and lib web3.js
version 1.2.4, and own blockchain node, and all worked fine but when I moving to AWS Etheruem Node (wss://{node_id}.wss.t.ethereum.managedblockchain.{aws_region}.amazonaws.com/?billingtoken={accessor_token}) for some blocks i get an error from AWS Etheruem Node - Error: Returned error: the message response is too large, please retry this request over HTTPS
.
Why it happen?
I know about these ways but can I use this code and this new AWS Etheruem Node without going to new libs like aws-websocket-provider.js
and processing blocks which has this err?
web3Wrapper.js:
const Web3 = require('web3');
const { WEB3_WS_URI } = require('../settings');
class Web3Wrapper {
constructor() {
return (async () => {
this.web3 = new Web3(await this.createProvider());
return this;
})();
}
async createProvider() {
const options = {
timeout: 30000, // ms
clientConfig: {
maxReceivedFrameSize: 100000000,
maxReceivedMessageSize: 100000000,
keepalive: true,
keepaliveInterval: 60000 // ms
},
reconnect: {
auto: true,
delay: 5000, // ms
maxAttempts: 5,
onTimeout: false
}
};
const provider = new Web3.providers.WebsocketProvider(WEB3_WS_URI, options);
provider.on('connection', () => logger.info('WS connected'));
provider.on('error', (err) => logger.error(`Error is WS: ${err.message}`));
provider.on('end', async () => {
logger.info('WS connection closed');
logger.info('Will try to reconnect in 1 second...');
await sleep(1);
this.web3.setProvider(await this.createProvider());
this.newBlocksSubscription = (
await this.web3.eth.subscribe('newBlockHeaders')
);
this.newBlocksSubscription.on('data', this.newBlocksCallback);
});
return provider;
}
getBlockWithTransactions.js:
async function getBlockWithTransactions(blockNumber) {
let block;
try {
logger.debug('Try to get block # %s', blockNumber)
block = await state.web3Wrapper.web3.eth.getBlock(blockNumber, true);
} catch (err) {
logger.error('getBlockWithTransactions(%s) gets error: %s', blockNumber, err);
throw new Web3Error('Error while calling `getBlock`');
}
if (!block) {
logger.warn('Can not find block %s, better to increase `LATEST_BLOCK_LAG`', blockNumber);
return;
}
return block;
}
piece of the log after switch to AWS Etheruem Node:
[2023-03-31 20:10:39] INFO (/app/main.js): Network is mainnet
[2023-03-31 20:10:50] INFO (/app/utils/syncWithBlockchain.js): Processing block 16949450 takes 0.988s
[2023-03-31 20:10:50] INFO (/app/utils/syncWithBlockchain.js): Processing block 16949451 takes 0.647s
[2023-03-31 20:10:51] INFO (/app/utils/syncWithBlockchain.js): Processing block 16949452 takes 0.812s
[2023-03-31 20:10:52] INFO (/app/utils/syncWithBlockchain.js): Processing block 16949453 takes 0.798s
[2023-03-31 20:10:53] INFO (/app/utils/syncWithBlockchain.js): Processing block 16949454 takes 0.687s
[2023-03-31 20:10:53] INFO (/app/utils/syncWithBlockchain.js): Processing block 16949455 takes 0.685s
[2023-03-31 20:10:54] ERROR (/app/utils/getBlockWithTransactions.js): getBlockWithTransactions(16949456) gets error: Error: Returned error: the message response is too large, please retry this request over HTTPS
[2023-03-31 20:10:54] ERROR (/app/utils/syncWithBlockchain.js): Error while calling `getBlock`
[2023-03-31 20:11:02] ERROR (/app/utils/getBlockWithTransactions.js): getBlockWithTransactions(16949456) gets error: Error: Returned error: the message response is too large, please retry this request over HTTPS
[2023-03-31 20:11:02] ERROR (/app/utils/syncWithBlockchain.js): Error while calling `getBlock`
[2023-03-31 20:11:13] ERROR (/app/utils/getBlockWithTransactions.js): getBlockWithTransactions(16949456) gets error: Error: Returned error: the message response is too large, please retry this request over HTTPS