xeroc / python-graphenelib

Python3 library for Graphene-based blockchains
MIT License
74 stars 60 forks source link

trx.ref_block_prefix == tapos_block_summary.block_id._hash[1].value() #144

Closed bitphage closed 4 years ago

bitphage commented 4 years ago

Despite the issue was addressed in b3d6cda4b6e7fb840dc8721b6ac864a4ee60c1fd, I started to get this this error time-to-time in my dexbot production instance.

Error means "referenced block num prefix != actual block prefix". Block prefix is taken from next block using "previous" field: block = ws.get_block_header(int(dynBCParams["last_irreversible_block_num"])+1)

Some ambiguity is caused by referencing block num using only 16 bits. This means, referenced block num should not be older than 65535 from head block. The only way I can reproduce this issue artificially is by referring to some old block, like this: dynBCParams["last_irreversible_block_num"] -= 70000

I'm not sure how it's happening in production, but I can guess there could be a reconnection to the next node and LIB on new node was shifted to the past (node out of sync). I added a debug to see LIB next time the issue will happen.

bitphage commented 4 years ago

Also, Transactionbuilder caches ref_block_num and ref_block_prefix in constructTx() with dict.update(self, self.tx.json()). I don't see how this cache is invalidated, but I see from the logs the same ref_block_num is being used from several hours to maybe a day.

xeroc commented 4 years ago

Good find ... fixed

bitphage commented 4 years ago

It appears the error was due to caching: ref_block was cached, and after "wraparound" ref_block_prefix became invalid.