Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): CDB-2128 Address nonce errors #1004

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

dbcfd
Copy link

@dbcfd dbcfd commented Apr 4, 2023

Per ethers-io/ethers.js#3812, nonce may be incorrectly incremented, which can produce off by one errors which we are currently seeing in QA and Clay

@linear
Copy link

linear bot commented Apr 4, 2023

CDB-2128 Nonce errors in Clay AND QA CAS

Coordinator: dbrowning

Investigator: dbrowning

Clay CAS:

https://us-east-2.console.aws.amazon.com/cloudwatch/home?region=us-east-2#logsV2:log-groups/log-group/$252Fecs$252Fceramic-tnet-cas/log-events/cas_anchor$252Fcas_anchor$252F7dd464817de349c5aab085d2ca1fa13c

2022-12-12T04:50:36.417-05:00	[2022-12-12T09:50:36.417Z] IMPORTANT: 'Sending transaction to Ethereum gnosischain network...'
2022-12-12T04:50:36.549-05:00	[2022-12-12T09:50:36.549Z] ERROR: Error: processing response error (body="{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32010,\"message\":\"OldNonce, Current nonce: 14598, nonce of rejected tx: 14597\"},\"id\":75}", error={"code":-32010}, requestBody="{\"method\":\"eth_sendRawTransaction\",\"params\":[\"0x02f89164823905846c2eb3c0846c2eb3ce825458941c124c86f7fc22e67974337e889a513b16a5703f80a50f0171122074908374996e263646907a2aa7d9bb264276d638ba0d8ce4d392e5b2aa1da87ac080a0fe8ad67d823ddc02de612df8e810ddabfec8bb2271ed29751783a573724b29eea05827cd0bf3d5c4f612270678a9c6e0a36329bc0948c914d129289837ed9c3bd2\"],\"id\":75,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://quiet-cool-firefly.xdai.discover.quiknode.pro/d524192eabefb55f8a9911ff4dccce042f650ae0/", code=SERVER_ERROR, version=web/5.7.1)
2022-12-12T04:50:36.549-05:00	at Logger.makeError (/cas/node_modules/ethersproject/logger/lib/index.js:238:21)
2022-12-12T04:50:36.549-05:00	at Logger.throwError (/cas/node_modules/ethersproject/logger/lib/index.js:247:20)
2022-12-12T04:50:36.549-05:00	at /cas/node_modules/ethersproject/web/lib/index.js:313:32
2022-12-12T04:50:36.549-05:00	at step (/cas/node_modules/ethersproject/web/lib/index.js:33:23)
2022-12-12T04:50:36.549-05:00	at Object.next (/cas/node_modules/ethersproject/web/lib/index.js:14:53)
2022-12-12T04:50:36.549-05:00	at fulfilled (/cas/node_modules/ethersproject/web/lib/index.js:5:58)
2022-12-12T04:50:36.549-05:00	at runMicrotasks (<anonymous>)
2022-12-12T04:50:36.549-05:00	at processTicksAndRejections (node:internal/process/task_queues:96:5) {
2022-12-12T04:50:36.549-05:00	reason: 'processing response error',
2022-12-12T04:50:36.549-05:00	code: 'SERVER_ERROR',
2022-12-12T04:50:36.549-05:00	body: '{"jsonrpc":"2.0","error":{"code":-32010,"message":"OldNonce, Current nonce: 14598, nonce of rejected tx: 14597"},"id":75}',
2022-12-12T04:50:36.549-05:00	error: Error: OldNonce, Current nonce: 14598, nonce of rejected tx: 14597
2022-12-12T04:50:36.549-05:00	at getResult (/cas/node_modules/ethersproject/providers/lib/json-rpc-provider.js:191:21)
2022-12-12T04:50:36.549-05:00	at processJsonFunc (/cas/node_modules/ethersproject/web/lib/index.js:356:22)
2022-12-12T04:50:36.549-05:00	at /cas/node_modules/ethersproject/web/lib/index.js:288:46
2022-12-12T04:50:36.549-05:00	at step (/cas/node_modules/ethersproject/web/lib/index.js:33:23)
2022-12-12T04:50:36.549-05:00	at Object.next (/cas/node_modules/ethersproject/web/lib/index.js:14:53)
2022-12-12T04:50:36.549-05:00	at fulfilled (/cas/node_modules/ethersproject/web/lib/index.js:5:58)
2022-12-12T04:50:36.549-05:00	at runMicrotasks (<anonymous>)
2022-12-12T04:50:36.549-05:00	at processTicksAndRejections (node:internal/process/task_queues:96:5) {
2022-12-12T04:50:36.549-05:00	code: -32010,
2022-12-12T04:50:36.549-05:00	data: undefined
2022-12-12T04:50:36.549-05:00	},
2022-12-12T04:50:36.549-05:00	requestBody: '{"method":"eth_sendRawTransaction","params":["0x02f89164823905846c2eb3c0846c2eb3ce825458941c124c86f7fc22e67974337e889a513b16a5703f80a50f0171122074908374996e263646907a2aa7d9bb264276d638ba0d8ce4d392e5b2aa1da87ac080a0fe8ad67d823ddc02de612df8e810ddabfec8bb2271ed29751783a573724b29eea05827cd0bf3d5c4f612270678a9c6e0a36329bc0948c914d129289837ed9c3bd2"],"id":75,"jsonrpc":"2.0"}',
2022-12-12T04:50:36.549-05:00	requestMethod: 'POST',
2022-12-12T04:50:36.549-05:00	url: 'https://quiet-cool-firefly.xdai.discover.quiknode.pro/d524192eabefb55f8a9911ff4dccce042f650ae0/',
2022-12-12T04:50:36.549-05:00	transaction: {
2022-12-12T04:50:36.549-05:00	type: 2,
2022-12-12T04:50:36.549-05:00	chainId: 100,
2022-12-12T04:50:36.549-05:00	nonce: 14597,
2022-12-12T04:50:36.549-05:00	maxPriorityFeePerGas: BigNumber { _hex: '0x6c2eb3c0', _isBigNumber: true },
2022-12-12T04:50:36.549-05:00	maxFeePerGas: BigNumber { _hex: '0x6c2eb3ce', _isBigNumber: true },
2022-12-12T04:50:36.549-05:00	gasPrice: null,
2022-12-12T04:50:36.549-05:00	gasLimit: BigNumber { _hex: '0x5458', _isBigNumber: true },
2022-12-12T04:50:36.549-05:00	to: '0x1C124c86f7fc22e67974337E889a513b16a5703f',
2022-12-12T04:50:36.549-05:00	value: BigNumber { _hex: '0x00', _isBigNumber: true },
2022-12-12T04:50:36.549-05:00	data: '0x0f0171122074908374996e263646907a2aa7d9bb264276d638ba0d8ce4d392e5b2aa1da87a',
2022-12-12T04:50:36.549-05:00	accessList: [],
2022-12-12T04:50:36.549-05:00	hash: '0xf1e0d645f0948f9076491c9df797b1953e8fecceab23ff8520969c7736338d46',
2022-12-12T04:50:36.549-05:00	v: 0,
2022-12-12T04:50:36.549-05:00	r: '0xfe8ad67d823ddc02de612df8e810ddabfec8bb2271ed29751783a573724b29ee',
2022-12-12T04:50:36.549-05:00	s: '0x5827cd0bf3d5c4f612270678a9c6e0a36329bc0948c914d129289837ed9c3bd2',
2022-12-12T04:50:36.549-05:00	from: '0x1C124c86f7fc22e67974337E889a513b16a5703f',
2022-12-12T04:50:36.549-05:00	confirmations: 0
2022-12-12T04:50:36.549-05:00	},
2022-12-12T04:50:36.549-05:00	transactionHash: '0xf1e0d645f0948f9076491c9df797b1953e8fecceab23ff8520969c7736338d46'
2022-12-12T04:50:36.549-05:00	}
2022-12-12T04:50:36.549-05:00	[2022-12-12T09:50:36.549Z] WARNING: 'Failed to send transaction; 0 retries remain'

QA CAS:

https://us-east-2.console.aws.amazon.com/cloudwatch/home?region=us-east-2#logsV2:log-groups/log-group/$252Fecs$252Fceramic-qa-cas/log-events/cas_anchor$252Fcas_anchor$252Fd8b1a8e4c9d34198bd7e72f4f2686700

2022-12-11T00:51:41.522-05:00	[2022-12-11T05:51:41.522Z] IMPORTANT: 'Sending transaction to Ethereum goerli network...'
2022-12-11T00:51:41.717-05:00	[2022-12-11T05:51:41.717Z] ERROR: Error: nonce has already been used [ See: https://links.ethers.org/v5-errors-NONCE_EXPIRED ] (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"jsonrpc\":\"2.0\",\"id\":65,\"error\":{\"code\":-32000,\"message\":\"nonce too low\"}}","error":{"code":-32000},"requestBody":"{\"method\":\"eth_sendRawTransaction\",\"params\":[\"0x02f89105821b6f846259008084625ce33e8254589441ee0c359d95970a83229d8e9801cc267239021780a50f01711220337eb7b11ff378b7f64e8d1a16bed17ffc2e0d4a69e0245a973396fa2a8f4be0c080a0415b4dfd2157f507aa3bfc0e832d1b6960afec5a5c1fe4cfbc63072d36ab49d6a072447e5a3228553dfa145982f6f6d527542ea8f742c8db6976d7dbf847024e59\"],\"id\":65,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"https://goerli.infura.io/v3/b6685df41e1647c4be0046dfa62a020b"}, method="sendTransaction", transaction="0x02f89105821b6f846259008084625ce33e8254589441ee0c359d95970a83229d8e9801cc267239021780a50f01711220337eb7b11ff378b7f64e8d1a16bed17ffc2e0d4a69e0245a973396fa2a8f4be0c080a0415b4dfd2157f507aa3bfc0e832d1b6960afec5a5c1fe4cfbc63072d36ab49d6a072447e5a3228553dfa145982f6f6d527542ea8f742c8db6976d7dbf847024e59", code=NONCE_EXPIRED, version=providers/5.7.2)
2022-12-11T00:51:41.717-05:00	at Logger.makeError (/cas/node_modules/ethersproject/logger/lib/index.js:238:21)
2022-12-11T00:51:41.717-05:00	at Logger.throwError (/cas/node_modules/ethersproject/logger/lib/index.js:247:20)
2022-12-11T00:51:41.717-05:00	at checkError (/cas/node_modules/ethersproject/providers/lib/json-rpc-provider.js:152:16)
2022-12-11T00:51:41.717-05:00	at JsonRpcProvider.<anonymous> (/cas/node_modules/ethersproject/providers/lib/json-rpc-provider.js:751:47)
2022-12-11T00:51:41.717-05:00	at step (/cas/node_modules/ethersproject/providers/lib/json-rpc-provider.js:48:23)
2022-12-11T00:51:41.717-05:00	at Object.throw (/cas/node_modules/ethersproject/providers/lib/json-rpc-provider.js:29:53)
2022-12-11T00:51:41.717-05:00	at rejected (/cas/node_modules/ethersproject/providers/lib/json-rpc-provider.js:21:65)
2022-12-11T00:51:41.717-05:00	at processTicksAndRejections (node:internal/process/task_queues:96:5) {
2022-12-11T00:51:41.717-05:00	reason: 'nonce has already been used',
2022-12-11T00:51:41.717-05:00	code: 'NONCE_EXPIRED',
2022-12-11T00:51:41.717-05:00	error: Error: processing response error (body="{\"jsonrpc\":\"2.0\",\"id\":65,\"error\":{\"code\":-32000,\"message\":\"nonce too low\"}}", error={"code":-32000}, requestBody="{\"method\":\"eth_sendRawTransaction\",\"params\":[\"0x02f89105821b6f846259008084625ce33e8254589441ee0c359d95970a83229d8e9801cc267239021780a50f01711220337eb7b11ff378b7f64e8d1a16bed17ffc2e0d4a69e0245a973396fa2a8f4be0c080a0415b4dfd2157f507aa3bfc0e832d1b6960afec5a5c1fe4cfbc63072d36ab49d6a072447e5a3228553dfa145982f6f6d527542ea8f742c8db6976d7dbf847024e59\"],\"id\":65,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://goerli.infura.io/v3/b6685df41e1647c4be0046dfa62a020b", code=SERVER_ERROR, version=web/5.7.1)
2022-12-11T00:51:41.717-05:00	at Logger.makeError (/cas/node_modules/ethersproject/logger/lib/index.js:238:21)
2022-12-11T00:51:41.717-05:00	at Logger.throwError (/cas/node_modules/ethersproject/logger/lib/index.js:247:20)
2022-12-11T00:51:41.717-05:00	at /cas/node_modules/ethersproject/web/lib/index.js:313:32
2022-12-11T00:51:41.717-05:00	at step (/cas/node_modules/ethersproject/web/lib/index.js:33:23)
2022-12-11T00:51:41.717-05:00	at Object.next (/cas/node_modules/ethersproject/web/lib/index.js:14:53)
2022-12-11T00:51:41.717-05:00	at fulfilled (/cas/node_modules/ethersproject/web/lib/index.js:5:58)
2022-12-11T00:51:41.717-05:00	at processTicksAndRejections (node:internal/process/task_queues:96:5) {
2022-12-11T00:51:41.717-05:00	reason: 'processing response error',
2022-12-11T00:51:41.717-05:00	code: 'SERVER_ERROR',
2022-12-11T00:51:41.717-05:00	body: '{"jsonrpc":"2.0","id":65,"error":{"code":-32000,"message":"nonce too low"}}',
2022-12-11T00:51:41.717-05:00	error: Error: nonce too low
2022-12-11T00:51:41.717-05:00	at getResult (/cas/node_modules/ethersproject/providers/lib/json-rpc-provider.js:191:21)
2022-12-11T00:51:41.717-05:00	at processJsonFunc (/cas/node_modules/ethersproject/web/lib/index.js:356:22)
2022-12-11T00:51:41.717-05:00	at /cas/node_modules/ethersproject/web/lib/index.js:288:46
2022-12-11T00:51:41.717-05:00	at step (/cas/node_modules/ethersproject/web/lib/index.js:33:23)
2022-12-11T00:51:41.717-05:00	at Object.next (/cas/node_modules/ethersproject/web/lib/index.js:14:53)
2022-12-11T00:51:41.717-05:00	at fulfilled (/cas/node_modules/ethersproject/web/lib/index.js:5:58)
2022-12-11T00:51:41.717-05:00	at processTicksAndRejections (node:internal/process/task_queues:96:5) {
2022-12-11T00:51:41.717-05:00	code: -32000,
2022-12-11T00:51:41.717-05:00	data: undefined
2022-12-11T00:51:41.717-05:00	},
2022-12-11T00:51:41.717-05:00	requestBody: '{"method":"eth_sendRawTransaction","params":["0x02f89105821b6f846259008084625ce33e8254589441ee0c359d95970a83229d8e9801cc267239021780a50f01711220337eb7b11ff378b7f64e8d1a16bed17ffc2e0d4a69e0245a973396fa2a8f4be0c080a0415b4dfd2157f507aa3bfc0e832d1b6960afec5a5c1fe4cfbc63072d36ab49d6a072447e5a3228553dfa145982f6f6d527542ea8f742c8db6976d7dbf847024e59"],"id":65,"jsonrpc":"2.0"}',
2022-12-11T00:51:41.717-05:00	requestMethod: 'POST',
2022-12-11T00:51:41.717-05:00	url: 'https://goerli.infura.io/v3/b6685df41e1647c4be0046dfa62a020b'
2022-12-11T00:51:41.717-05:00	},
2022-12-11T00:51:41.717-05:00	method: 'sendTransaction',
2022-12-11T00:51:41.717-05:00	transaction: {
2022-12-11T00:51:41.717-05:00	type: 2,
2022-12-11T00:51:41.717-05:00	chainId: 5,
2022-12-11T00:51:41.717-05:00	nonce: 7023,
2022-12-11T00:51:41.717-05:00	maxPriorityFeePerGas: BigNumber { _hex: '0x62590080', _isBigNumber: true },
2022-12-11T00:51:41.717-05:00	maxFeePerGas: BigNumber { _hex: '0x625ce33e', _isBigNumber: true },
2022-12-11T00:51:41.717-05:00	gasPrice: null,
2022-12-11T00:51:41.717-05:00	gasLimit: BigNumber { _hex: '0x5458', _isBigNumber: true },
2022-12-11T00:51:41.717-05:00	to: '0x41Ee0C359D95970A83229D8e9801cc2672390217',
2022-12-11T00:51:41.717-05:00	value: BigNumber { _hex: '0x00', _isBigNumber: true },
2022-12-11T00:51:41.717-05:00	data: '0x0f01711220337eb7b11ff378b7f64e8d1a16bed17ffc2e0d4a69e0245a973396fa2a8f4be0',
2022-12-11T00:51:41.717-05:00	accessList: [],
2022-12-11T00:51:41.717-05:00	hash: '0xf98597323e510f45e45745da0c060adf57de407d16051571272ee3cf747877e1',
2022-12-11T00:51:41.717-05:00	v: 0,
2022-12-11T00:51:41.717-05:00	r: '0x415b4dfd2157f507aa3bfc0e832d1b6960afec5a5c1fe4cfbc63072d36ab49d6',
2022-12-11T00:51:41.717-05:00	s: '0x72447e5a3228553dfa145982f6f6d527542ea8f742c8db6976d7dbf847024e59',
2022-12-11T00:51:41.717-05:00	from: '0x41Ee0C359D95970A83229D8e9801cc2672390217',
2022-12-11T00:51:41.717-05:00	confirmations: 0
2022-12-11T00:51:41.717-05:00	},
2022-12-11T00:51:41.717-05:00	transactionHash: '0xf98597323e510f45e45745da0c060adf57de407d16051571272ee3cf747877e1'
2022-12-11T00:51:41.717-05:00	}
2022-12-11T00:51:41.718-05:00	[Sun, 11 Dec 2022 05:51:41 GMT] service=ethereum type=nonceExpired nonce=7023
2022-12-11T00:51:41.720-05:00	[2022-12-11T05:51:41.720Z] WARNING: 'Updating PROCESSING requests to PENDING so they are retried in the next batch because an error occured while creating the anchors: Error: nonce has already been used [ See: https://links.ethers.org/v5-errors-NONCE_EXPIRED ] (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\\"jsonrpc\\":\\"2.0\\",\\"id\\":65,\\"error\\":{\\"code\\":-32000,\\"message\\":\\"nonce too low\\"}}","error":{"code":-32000},"requestBody":"{\\"method\\":\\"eth_sendRawTransaction\\",\\"params\\":[\\"0x02f89105821b6f846259008084625ce33e8254589441ee0c359d95970a83229d8e9801cc267239021780a50f01711220337eb7b11ff378b7f64e8d1a16bed17ffc2e0d4a69e0245a973396fa2a8f4be0c080a0415b4dfd2157f507aa3bfc0e832d1b6960afec5a5c1fe4cfbc63072d36ab49d6a072447e5a3228553dfa145982f6f6d527542ea8f742c8db6976d7dbf847024e59\\"],\\"id\\":65,\\"jsonrpc\\":\\"2.0\\"}","requestMethod":"POST","url":"https://goerli.infura.io/v3/b6685df41e1647c4be0046dfa62a020b"}, method="sendTransaction", transaction="0x02f89105821b6f846259008084625ce33e8254589441ee0c359d95970a83229d8e9801cc267239021780a50f01711220337eb7b11ff378b7f64e8d1a16bed17ffc2e0d4a69e0245a973396fa2a8f4be0c080a0415b4dfd2157f507aa3bfc0e832d1b6960afec5a5c1fe4cfbc63072d36ab49d6a072447e5a3228553dfa145982f6f6d527542ea8f742c8db6976d7dbf847024e59", code=NONCE_EXPIRED, version=providers/5.7.2)'
2022-12-11T00:51:41.726-05:00	[Sun, 11 Dec 2022 05:51:41 GMT] service=db type=request action=update id=65f42dd4-40a3-4beb-ae49-534bf3d9063a status=0 pinned=true createdAt=1670737762326 updatedAt="Sun Dec 11 2022 05:51:41 GMT+0000 (Coordinated Universal Time)" cid=bagcqceramcedgk3eb25rwp2mkf4hth7axxrp7fscm7qosgs4foubzltafnya streamId=kjzl6cwe1jw14asaqhgnquz9359pc053z537e5ias9fnojdjqyxvstjxruuz6pz message="Request is pending."
2022-12-11T00:51:41.730-05:00	[Sun, 11 Dec 2022 05:51:41 GMT] service=anchor type=anchorRequests acceptedRequestsCount=1 alreadyAnchoredRequestsCount=0 anchoredRequestsCount=0 conflictingRequestCount=0 failedRequestsCount=0 failedToPublishAnchorCommitCount=0 unprocessedRequestCount=0 pendingRequestsCount=1 candidateCount=1 anchorCount=0 canRetryCount=1 reanchoredCount=0
2022-12-11T00:51:41.731-05:00	[2022-12-11T05:51:41.731Z] ERROR: 'Error when anchoring: Error: nonce has already been used [ See: https://links.ethers.org/v5-errors-NONCE_EXPIRED ] (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\\"jsonrpc\\":\\"2.0\\",\\"id\\":65,\\"error\\":{\\"code\\":-32000,\\"message\\":\\"nonce too low\\"}}","error":{"code":-32000},"requestBody":"{\\"method\\":\\"eth_sendRawTransaction\\",\\"params\\":[\\"0x02f89105821b6f846259008084625ce33e8254589441ee0c359d95970a83229d8e9801cc267239021780a50f01711220337eb7b11ff378b7f64e8d1a16bed17ffc2e0d4a69e0245a973396fa2a8f4be0c080a0415b4dfd2157f507aa3bfc0e832d1b6960afec5a5c1fe4cfbc63072d36ab49d6a072447e5a3228553dfa145982f6f6d527542ea8f742c8db6976d7dbf847024e59\\"],\\"id\\":65,\\"jsonrpc\\":\\"2.0\\"}","requestMethod":"POST","url":"https://goerli.infura.io/v3/b6685df41e1647c4be0046dfa62a020b"}, method="sendTransaction", transaction="0x02f89105821b6f846259008084625ce33e8254589441ee0c359d95970a83229d8e9801cc267239021780a50f01711220337eb7b11ff378b7f64e8d1a16bed17ffc2e0d4a69e0245a973396fa2a8f4be0c080a0415b4dfd2157f507aa3bfc0e832d1b6960afec5a5c1fe4cfbc63072d36ab49d6a072447e5a3228553dfa145982f6f6d527542ea8f742c8db6976d7dbf847024e59", code=NONCE_EXPIRED, version=providers/5.7.2)'
2022-12-11T00:51:41.731-05:00	[2022-12-11T05:51:41.731Z] ERROR: 'Exiting'

@@ -90,7 +90,7 @@ async function makeCeramicCore(
anchorServiceUrl,
// TODO CDB-2317 Remove `indexing` config when Ceramic Core allows that
indexing: {
db: "TODO",
db: 'TODO',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier

}
}
}
return function (req: Request, _res: Response, next: NextFunction) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier

@@ -15,9 +15,11 @@ export class CeramicAnchorServer extends Server {
super(true)

this.app.set('trust proxy', true)
this.app.use(bodyParser.raw({inflate: true, type: 'application/vnd.ipld.car'}))
this.app.use(bodyParser.raw({ inflate: true, type: 'application/vnd.ipld.car' }))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier

@@ -39,7 +38,7 @@ export enum METRIC_NAMES {
// Anchor Service (histograms)

// request that moves from ready -> processing
READY_PROCESSING_MS = "ready_processing_ms",
READY_PROCESSING_MS = 'ready_processing_ms',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier

@dbcfd dbcfd force-pushed the cdb-2128-nonce-error branch from a25249b to 118fcec Compare April 6, 2023 17:51
@dbcfd dbcfd requested a review from ukstv April 6, 2023 20:26
Copy link
Contributor

@stbrody stbrody left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most important note is to avoid changing the format of the AnchorProof.

src/models/transaction.ts Outdated Show resolved Hide resolved
src/services/anchor-service.ts Outdated Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
const baseFee = maxFeePerGas.sub(maxPriorityFeePerGas)
txData.maxFeePerGas = baseFee.add(nextPriorityFee)
// must be greater than baseFee + maxPriorityFeePerGas
txData.maxFeePerGas = addPadding(baseFee + nextPriorityFee)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we adding padding here if we already added padding in increaseGasPricePerAttempt? Is this redundant?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On upgrading ethers, we run into underpriced transaction errors. I'm not sure if ethers changed something in the data they report back, but this is required to not have underpriced transaction errors.

if (attempt == 0 || previousGas == undefined) {
return increaseEstimate
): bigint {
if (previousGas == undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this is a behavior change to the gas logic. Previously we would add an increasing amount of padding per attempt on top of the gas estimate we get from ethers. So the first attempt we'd just use the gas estimate from ethers directly. The second attempt we'd add 10% on top of the estimate, and the third time we'd add 20% on top of the estimate.
In this new version we're just always adding 10% on top of the estimate every time.

I don't feel strongly about which logic is better, but could we possibly separate the changes to our estimation logic from the code changes required to keep the same logic with upgrading to the new version of the ethers package, each into their own PR?

Copy link
Author

@dbcfd dbcfd Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's a few things going on here

  1. const prevPriorityFee = BigInt(txData.maxPriorityFeePerGas || feeData.maxPriorityFeePerGas)
    makes this a little harder to follow, so it might make sense to pass both previous and estimate in to increase gas, rather than combining the values in set gas. If there's a previous, that always gets passed in as the estimate
  2. Once we have a previous (say x), we will pass that in, and multiply that by 10%. x * 110% * 110% is always more than x * 120%. Double check my code reading there, but I don't think we'll ever choose increaseEstimate.
  3. As mentioned above, we run into underpriced transaction with the ethers upgrade. We would have to change the gas logic before the ethers upgrade if we want to split the PRs.

Copy link
Contributor

@ukstv ukstv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like calculation logic is okay. Minor technical improvements could be handy.

And emulation of StaticJsonRpcProvider! That could require some additional refactoring though: I am not sure if staticNetwork would work without giving explicit network to the provider.

pnpm-lock.yaml Outdated Show resolved Hide resolved
src/services/blockchain/__tests__/eth-bc-service.test.ts Outdated Show resolved Hide resolved
@ukstv
Copy link
Contributor

ukstv commented Apr 11, 2023

@dbcfd Oh, lovely ethers: https://github.com/ceramicnetwork/ceramic-anchor-service/actions/runs/4670215624/jobs/8269672491#step:10:3555

At one point I thought maybe we could ditch ethers with viem altogether.

@jxom
Copy link

jxom commented Apr 11, 2023

At one point I thought maybe we could ditch ethers with viem altogether.

viem author here! We are happy to help 😉

Per ethers-io/ethers.js#3812, nonce may be
incorrectly incremented, which can produce off by one errors which
we are currently seeing in QA and Clay
@dbcfd dbcfd force-pushed the cdb-2128-nonce-error branch from 61cebb5 to e724438 Compare April 13, 2023 19:40
@dbcfd dbcfd requested a review from stbrody April 13, 2023 20:54
Copy link
Contributor

@stbrody stbrody left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only actually important comment is making sure that we're serializing the date timestamp into the ipfs proof correctly

@@ -404,7 +404,7 @@ export class AnchorService {
if (this.includeBlockInfoInAnchorProof) {
ipfsAnchorProof = {
blockNumber: tx.blockNumber,
blockTimestamp: tx.blockTimestamp,
blockTimestamp: tx.blockTimestamp.getUTCDate(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this returns the date of the month. Ie for a Data object created for today it returns 17. I think you want the unix timestamp - I believe it's getTime() that you want, but do be careful of units. I'm not sure if that returns seconds or millis, and we need to make sure whatever we use matches what we are currently doing.

The fact that this change didn't cause any tests to fail is actually a bit worrying, maybe see if you can add a test that would catch this?

Please also make sure to do some manual testing to ensure that the AnchorProofs created before and after this change look the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Will fix that and check the test.

@@ -115,20 +126,50 @@ function handleTimeoutError(transactionTimeoutSecs: number): void {
function make(config: Config): EthereumBlockchainService {
const ethereum = config.blockchain.connectors.ethereum
const { host, port, url } = ethereum.rpc
let network
try {
network = Network.from(ethereum.network)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... this is likely to be a breaking change as now the network option is required in the config even when using an infura url (which implies the network and so network wasn't previously required).

That's fine since we're the only ones running a CAS, just something to look out for when we go to deploy. We should double check we have the network set so things don't break on the upgrade

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: I see it's not actually required as if its not set we fall back to the non-static behavior. But that could cause our infura endpoint to be pummeled with chainid calls and blow up our bill (this happened in the past) so we'll still want to be really careful here and make sure have the network flag set on all 3 envs, and monitor our infura account as this gets deployed to various envs.

provider = new ethers.JsonRpcProvider(hostPort)
}
} else if (network) {
logger.imp(`Connecting ethereum to etherscan provider for network ${ethereum.network}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by "etherscan" provider here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options make it so only etherscan works, since that's we use for our tests. All other providers would need host/port, and preferably name.

alchemy: "-",
ankr: "-",
cloudflare: "-",
etherscan: ethereum.account.privateKey,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes all providers other than etherscan, and sets the private key for etherscan.

} else if (host && port) {
logger.imp(`Connecting ethereum provider to host: ${host} and port ${port}`)
provider = new ethers.providers.StaticJsonRpcProvider(`${host}:${port}`)
const hostPort = `${host}:${port}`
if (network) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can reduce code duplication by creating an empty options object and adding the staticNetwork field to it if network is set. Then we can always just pass the options object to the JSONRpcProvider constructor and not need the extra if(network) conditional in both blocks?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will reduce the duplication.

@dbcfd dbcfd requested a review from stbrody April 21, 2023 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants