eosnetworkfoundation / eos-evm-contract

EOS EVM
Other
22 stars 15 forks source link

History index is not correct #551

Closed yarkinwho closed 1 year ago

yarkinwho commented 1 year ago

Discovered through some messy record in explorer:

History index is wrong -> history nonce is wrong -> reply transaction will report wrong deployment address for contracts -> mess up explorer

Still investigating why the history index is wrong.

yarkinwho commented 1 year ago

Confirmed it's a deterministic bug.

yarkinwho commented 1 year ago

The root cause is when indexing the changes, something like this is used to locate the first block to process: auto source_data{storage ? source.lower_bound(db::to_slice(start_key), false) : source.find(db::to_slice(start_key), false)};

The source.find part will only work if we have changes in every block (obviously it is the case if we have gas fee to miner, but we do not).

When we failed to locate the start block, the index process will not start. This will cause missing index in the db.

Later when RPC try to locate historical data, it will be point to wrong block to read data from and caused this issue.

Fixed by always use lower_bound

yarkinwho commented 1 year ago

Note that for deployment, we need to replay from genesis for eos-evm-node Then we need a re-index for explorer as well

yarkinwho commented 1 year ago

Fixed some extra issues introduced during copying over smart contract verification records. Now document the migration process here for record:

in old db:

\copy smart_contracts to '/home/ubuntu/smart_contracts.csv' csv;

\copy smart_contracts_additional_sources to '/home/ubuntu/smart_contracts_additional_sources.csv' csv;

\copy contract_methods to '/home/ubuntu/contract_methods.csv' csv;

in new db:

\copy smart_contracts from '/home/ubuntu/smart_contracts.csv' csv;

\copy smart_contracts_additional_sources from '/home/ubuntu/smart_contracts_additional_sources.csv' csv;

\copy contract_methods from '/home/ubuntu/contract_methods.csv' csv;

SELECT setval('smart_contracts_id_seq', COALESCE((SELECT MAX(id)+1 FROM smart_contracts), 1), false);

SELECT setval('smart_contracts_additional_sources_id_seq', COALESCE((SELECT MAX(id)+1 FROM smart_contracts_additional_sources), 1), false);

SELECT setval('contract_methods_id_seq', COALESCE((SELECT MAX(id)+1 FROM contract_methods), 1), false);