eosauthority / eosio-watcher-plugin

EOSIO watcher plugin: HTTP POST to endpoint for on chain actions
MIT License
66 stars 30 forks source link

Added additional processing to include inline transactions #5

Closed acoutts closed 6 years ago

acoutts commented 6 years ago

With normal user->user transfers, the action is visible in block_state->trxs, but for transactions coming from a smart contract they will not be visible in this area. Originally this code would successfully detect the inline actions and add them to the actions_queue, but because none of the inline transaction IDs were found in block_state->trxs when it was checked in on_accepted_block, the actions were all thrown away and never notified.

By looking additionally within block_state->block->transactions on each new block, we can see and match on these inline transactions as they have a different pattern than the normal transactions.

Specifically, the block_state->block->transactions->trx items look like this when it's a normal transaction from a user:

[1,{"signatures":["SIG_K1_Jx1D24xrkDN2Z36saZ6Rm2yNW9J73CuA5cuZWHBPZnd1p3gYtMetMjy8XmEzmSmBXxDAtrfuN35mvHcEb9GctWoYZSv3We"],"compression":"none","packed_context_free_data":"","packed_trx":"51fc875bd748e34fd082000000000100a6823403ea3055000000572d3ccdcd0110f2d414217315d600000000a8ed32323110f2d414217315d620f2d414217315d6010000000000000004454f5300000000103135333536333835373934393739323800"}]

And this when it's a transaction sent from a smart contract, where the second array member is the associated transaction ID:

[0,"411ddc7fa7ea7737c8b318b2f08b5ece5c07335a7e70173aabdcb94c7cb9418a"]}

By iterating through all of the block_state->block->transactions->trx and checking if they contain a transaction ID, we can narrow down to process only the inline ones.

After making these modifications, the watcher plugin now catches all actions including the inline ones, so this can now be used to watch actions coming out of a smart contract.

A better future implementation would be to only loop through the block_state->block->transactions->trx items and unpack the transaction data in there to get at the transaction ID from the 'normal' transactions, to prevent having to run two loops on each block.

sim31 commented 6 years ago

As far as I know there are only deferred transactions. I think that's what you mean. Only actions can be inline. Can you give an example how are you generating those transactions from contract?

I think this plugin wasn't tested with deferred transactions, so this is probably a necessary change.

As I understand it block_state->block->transactions contain all transactions, not just deferred ones, right? In that case, I think it would be a better idea to modify existing loop to iterate through block_state->block->transactions instead of adding another loop. Would be much more efficient.

eosauthority commented 6 years ago

@sim31 - please feel free to send the pull request with other changes

sim31 commented 6 years ago

Ahh, we would need to unpack all the normal transactions then to get tx ids. Not sure if it's worth it, then.

acoutts commented 6 years ago

I just submitted https://github.com/eosauthority/eosio-watcher-plugin/pull/6 with the new change