EOSIO / eos

An open source smart contract platform
https://developers.eos.io/manuals/eos
MIT License
11.27k stars 3.6k forks source link

Sync some contracts transactions from mainnet #5784

Closed jacktang closed 6 years ago

jacktang commented 6 years ago

Hello,

Follow the guide(https://medium.com/@cc32d9/running-a-full-eos-mainnet-node-d7da2d3b154f) I setup the synchronization with mainnet. However, in my dapp, I only want to watch some smart contracts' transactions. So my questions are:

1) Can I sync data from some specified block rather than block 0? 2) Can I filter transactions using contract address(account name)? I just read chain_plugin source code, and don't understand contract-whitelist option very much.

Thanks!

jgiszczak commented 6 years ago

You can not sync to the chain without starting from block 0.

To see only some contracts' transactions, simply name each account in your nodeos config.ini:

contract-whitelist = someaccount1
contract-whitelist = someaccount2
contract-whitelist = someaccount3

where someaccount1 is the account on which set contract was executed for the contract you are interested in. You may have as many or as few contract-whitelist = entries as you need.

To maintain the sanity of your node, you should include whitelist entries for all system contracts:

contract-whitelist = eosio
contract-whitelist = eosio.token
contract-whitelist = eosio.msig

You probably also want to see activity generated by those accounts, so you should include corresponding author-whitelist entries:

actor-whitelist = someaccount1
actor-whitelist = someaccount2
actor-whitelist = someaccount3

You definitely want to see activity generated by the system accounts:

actor-whitelist = eosio
actor-whitelist = eosio.token
actor-whitelist = eosio.msig
jacktang commented 6 years ago

@jgiszczak thanks for the reply :), and can I set some option to skip syncing the unrelated transactions? because the smart contract was deployed serval days ago, and it is easy to get the first block of the smart contract form mainnet block explorer.

jgiszczak commented 6 years ago

The whitelist functions as an exclusive list. Anything not present in the whitelist will be ignored.

jacktang commented 6 years ago

@jgiszczak I saw some filter-on config

filter-on = eosio.token:transfer:

so what's the difference between filter-on and contract-whitelist? BTW: author-whitelist is removed in v1.3.0?

jgiszczak commented 6 years ago

filter-on is a setting for the history_plugin. It determines what transaction history will be tracked. contract-whitelist is a setting of the chain itself. When there are entries in the whitelist, those and only those contracts are allowed to execute transactions on the chain, regardless of filter settings.

Sorry, author-whitelist was an error. The correct setting is actor-whitelist. I've edited my post.

jacktang commented 6 years ago

@jgiszczak contract-whitelist still works on chain hard-replay mode? I tried to import offline blocks archived data with setting contract-whitelist (the contract account had only 3 tx), and I see a lot of logging like

2018-10-11T09:11:36.412 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:37.714 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:37.714 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:39.324 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:40.891 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:42.190 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:42.190 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:43.930 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:45.368 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:46.863 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:48.105 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:49.526 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:50.909 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:52.224 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference
2018-10-11T09:11:53.189 thread-0   wabt.hpp:622                  translate_one        ] misaligned reference

I see some logs are produced by other contracts. why? should only import the contracts which show in whitelist?

jgiszczak commented 6 years ago

When replaying mainnet, the misaligned reference complaints from wabt are expected and benign.

If you are importing a block archive, the whitelist had no chance to take affect for any blocks in the archive, as they have already been processed.

If you are syncing with some existing public network, the whitelist and blacklist settings aren't all that helpful to you. (And I should have said so at the beginning, since you did mention mainnet. My apologies for the oversight.) Instead, use the filter settings for the plugin you are using, such as mongodb-filter-on = and mongodb-filter-out =. Your copy of the chain is required to have all transactions accepted by its producers, even if they are of no interest to you. However the data you track in some external searchable form can be filtered to include only transactions you care about.

Your dapp can then query your mongodb instance and it will retrieve only the transactions that match the filter settings and your search criteria.