DemocracyEarth / wallet

Censorship resistant democracies.
https://democracy.earth
MIT License
1.5k stars 286 forks source link

Removed on-chain events are not removed from database #561

Open darcher-framework opened 3 years ago

darcher-framework commented 3 years ago

Description

Smart contract events like submitting a new proposal or voting can be removed due to chain reorganization. However, in the periodical syncing task with blockchain, the DApp does not consider and handle the case when a previous emitted event is then removed.

This bug affects various functionalities including submitting new proposal, voting, processing a proposal and so on.

Reproduce Steps

One reproduce example is given below.

  1. submit a new proposal by sending a transaction
  2. mine a block and execute the transaction
  3. at this time, the DApp has noticed the new proposal event and add it to database
  4. chain reorganization happens, where the previous event is removed
  5. the proposal record is still in Database and is shown to users.
  6. Then if the user tries to vote, it will get the error, which means the proposal does not exist and the vote transaction will always fail. image

Expected Behaviour

The events removed by chain reorganization should also be removed from database of DApp, making the DApp consistent with data stored in smart contracts.