omni / poa-bridge

POA <-> Ethereum bridge for self transfers of POA native token to POA20 (ERC20 representation). Not supported. Use TokenBridge instead
https://github.com/poanetwork/token-bridge
GNU General Public License v3.0
79 stars 38 forks source link

Avoid double send for transactions when handle contract events #44

Open akolotov opened 6 years ago

akolotov commented 6 years ago

Currently the bridge could send the same transactions several times if the database is not updated properly.

The following changes could be introduced:

  1. To handle Deposit() event and avoid invocation of deposit() several times for the same origin transaction:

For Foreign chain it is necessary to check that

depositsSigned(sha3(ValidatorAddress, sha3(HomeDepositSender, Value, HomeTransactionHash)))

returns false and invoke deposit() in this case only.


  1. To handle Withdraw() event on the Foreign side and avoid invocation of submitSignature() several times for the same 'message'

For Foreign chain it is necessary to check that

messagesSigned(sha3(ValidatorAddress, sha3(message)))

returns false and invoke submitSignature() in this case only.


  1. To handle CollectedSignatures() event on the Foreign side and avoid invocation of withdraw() several times for the the same origin transaction

For Home chain it is necessary to check that

withdraws(ForeignTransactionHash)

returns false and invoke withdraw() in this case only.

rstormsf commented 6 years ago

very good explanation one more stategy to this is to run estimateGas it should succeed

akolotov commented 6 years ago

my expectation is that estimateGas will require more time to check tx. But it needs to be measured first of course.