eos icon indicating copy to clipboard operation
eos copied to clipboard

Limitation of account history for token receiver of eosio.token transfer action

Open CharlesJu1 opened this issue 8 years ago • 17 comments

The filter-on option takes the form of receiver:action:actor, where actor can be left blank. The receiver part can not be left blank.

For the eosio.token contract, with any given receiver, if I want to be able to check all the token transferred to that receiver from all different actors, I could not do that with the current filter-on mechanism.

Does it make sense to allow the receiver in the filter-on option to be blank as well?

Note that a transfer action will trigger three action trace with eosio.token, user, tester as the receiver respectively.

easypayx@easypayxs-MacBook-Pro:~/eosio-commands $ cleos push action eosio.token transfer '[ "user", "tester", "25.0000 EOS", "m" ]' -p user
executed transaction: 00a9a3e1e109682496fe1c3730473f85be687cd2c362455c9ea72e2435993bbc  128 bytes  2177 us
#   eosio.token <= eosio.token::transfer        {"from":"user","to":"tester","quantity":"25.0000 EOS","memo":"m"}
#          user <= eosio.token::transfer        {"from":"user","to":"tester","quantity":"25.0000 EOS","memo":"m"}
#        tester <= eosio.token::transfer        {"from":"user","to":"tester","quantity":"25.0000 EOS","memo":"m"}

CharlesJu1 avatar Jun 04 '18 05:06 CharlesJu1

The history plugin keeps actions that match the filter in shared memory. If it allowed a blank receiver or action, then it would open up a ram-filling attack.

#3757 (merged) doesn't meet your needs?

tbfleming avatar Jun 04 '18 14:06 tbfleming

#3757 solves half my problem. It allows me to retrieve all the transfer actions where an account is the sender. If given an account I want to see which other accounts does it receive token from, I could not do it. I noticed the current filter-on allows a "*", which will set the bypass_filter to true.

For the ram-filling attack, if the contract name is also added to the filter-on option, that would help. That is, if the filter-on takes the following form: contract:action:actor:receiver and we require the contract name must be present while all others can be left blank. That would give a full node control on what to filter and not open up a ram-filling attack, right?

CharlesJu1 avatar Jun 04 '18 14:06 CharlesJu1

"*" is for testing purposes only.

Contracts ignore actions they don't understand. e.g. if someone sent large actions named foo to eosio.token, it would ignore them and the chain would consider them valid. If filter-on's action was empty, it'd store those actions.

tbfleming avatar Jun 04 '18 14:06 tbfleming

I see. So a blank action still open up a ram-filling attack. Then what about we require contract and action must be specified, but actor and receiver can be left blank?

CharlesJu1 avatar Jun 04 '18 14:06 CharlesJu1

Do you have a small number of accounts that you need to track deposits to? e.g. an exchange account? If so then this should work: --filter-on foo:transfer:. This will capture all transfers to and from foo. e.g. where I did this with useraaaaaaaa:

$ cleos get actions useraaaaaaaa
#  seq  when                              contract::action => receiver      trx id...   args
================================================================================================================
#   13   2018-06-04T14:54:55.000     eosio.token::transfer => useraaaaaaaa  7b2d727c... {"from":"useraaaaaaab","to":"useraaaaaaaa","quantity":"0.000...
#   14   2018-06-04T14:54:55.000     eosio.token::transfer => useraaaaaaaa  9ee05961... {"from":"useraaaaaaac","to":"useraaaaaaaa","quantity":"0.000...
#   15   2018-06-04T14:54:55.000     eosio.token::transfer => useraaaaaaaa  0dc4f738... {"from":"useraaaaaaad","to":"useraaaaaaaa","quantity":"0.000...
#   16   2018-06-04T14:54:55.000     eosio.token::transfer => useraaaaaaaa  bf66d5e3... {"from":"useraaaaaaaj","to":"useraaaaaaaa","quantity":"0.000...
#   17   2018-06-04T14:54:56.500     eosio.token::transfer => eosio.token   e7c99c74... {"from":"useraaaaaaaa","to":"useraaaaaaag","quantity":"0.000...
#   18   2018-06-04T14:54:56.500     eosio.token::transfer => useraaaaaaaa  e7c99c74... {"from":"useraaaaaaaa","to":"useraaaaaaag","quantity":"0.000...
#   19   2018-06-04T14:54:56.500     eosio.token::transfer => useraaaaaaaa  cc9e3bde... {"from":"useraaaaaaag","to":"useraaaaaaaa","quantity":"0.000...
#   20   2018-06-04T14:54:56.500     eosio.token::transfer => useraaaaaaaa  c111b0af... {"from":"useraaaaaaai","to":"useraaaaaaaa","quantity":"0.000...
#   21   2018-06-04T14:54:56.500     eosio.token::transfer => useraaaaaaaa  3caf199f... {"from":"useraaaaaaaf","to":"useraaaaaaaa","quantity":"0.000...
...

tbfleming avatar Jun 04 '18 15:06 tbfleming

Actually our Dapp aims to serve a lot users that will do actions similar to token transfer. For every account, we would like to provide user the ability to check all the transactions coming in or out of his account. If there are only a small number of accounts to track, we can use what you mentioned above to meet the requirement. But fortunately/unfortunately, we are going to have a lot accounts to track. If you think contract:action:actor:receiver is ok, I can implement it and submit for review.

CharlesJu1 avatar Jun 04 '18 15:06 CharlesJu1

contract:action:actor:receiver sounds good.

tbfleming avatar Jun 04 '18 15:06 tbfleming

It will probably need to maintain backwards compatibility, so should handle both the 4-colon and 3-colon forms.

tbfleming avatar Jun 04 '18 15:06 tbfleming

Got it.

CharlesJu1 avatar Jun 04 '18 15:06 CharlesJu1

The amount of map lookups it takes to do this got excessive, so I'm now leaning toward dropping backward compatibility. Maybe something like this: --filter-on contract:action:account? contract and action would be required, account would be optional. If account is present it would match either actor or receiver.

tbfleming avatar Jun 06 '18 13:06 tbfleming

@rbw3821 thoughts?

tbfleming avatar Jun 06 '18 13:06 tbfleming

I don't see how this is going to cut down on explosive memory growth over the long term. If you have a private contract, that would be one thing, but eosio.token:transfer: is going to be used heavily on the public blockchain so you're going to get everyone's transfers with that filter, and over the long term that's going to require huge amounts of memory. I think this use case should be using a db plugin to store and query efficiently.

rbw3821 avatar Jun 06 '18 20:06 rbw3821

In our case, we will have a private contract that allows users to transfer some kind of asset among them and we would like to be able to show users their asset history coming in or out of their accounts. I would imagine many dapps will have this need. Thus we are looking for a way to be able to just track the related contract actions running on our own full node. What is the difference between history plugin and a db plugin? Which existing plugin is a db plugin so I can take a look?

CharlesJu1 avatar Jun 06 '18 23:06 CharlesJu1

A db plugin mirrors content (transactions, etc.) to a db. Your app then interacts with the db. The history plugin with the --filter-on option puts matching actions into a multi-index map. You can then use cleos to query the map. Basically, with the history plugin, memory is your database, and it will eventually fill up.

As for available db plugins, this is basically an "exercise for the reader". The mongo db plugin in the source code no longer works and is no longer maintained. There is an sql db plugin in development by the community. I've not tracked the status of that. Perhaps you could participate in that or roll your own.

rbw3821 avatar Jun 07 '18 13:06 rbw3821

Got it. I also noticed from source code that history_plugin does not require mongo db plugin. Given the current --filter-on option can take the form of eosio.token:transfer: which will also grow the memory continuously, is it ok to make a change as Todd suggested as a partial solution? For Dapp that needs frequent fast queries and not that many history to keep track, this memory database is a good fit. Once the db plugin is developed by the community, Dapp can have more choices.

CharlesJu1 avatar Jun 07 '18 14:06 CharlesJu1

This pull request is very useful. I merge it locally and save all the data to disk, not Ram. Thank you CharlesJu1.

datnv-ibl avatar Jun 18 '18 02:06 datnv-ibl

Solved by tbfleming.

If you still have the problem and wish to discuss further, please post it in https://eosio.stackexchange.com. To keep things organised, Github issues are intended for bugs reporting and features tracking, and Stack Exchange is the right place for any technical support discussions. Thanks!

halsaphi avatar Oct 30 '18 07:10 halsaphi