Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postage/events: pkg for postage events and syncing with events #934

Closed
wants to merge 1 commit into from

Conversation

zelig
Copy link
Member

@zelig zelig commented Nov 10, 2020

this incomplete PR implements the go side of postage events and syncing with these events as per #920
see AP https://hackmd.io/o8RGsNwZSN6IE0lkBAZCPw?both

known to be missing:

  • tests (unclear to me how to mock types.Log events without ethclient calls on actual contracts.
  • handling of reorgs types.Log.Removed field and/or 'n-block confirmation delay'

@zelig zelig self-assigned this Nov 10, 2020
Base automatically changed from stamper to storage-incentives November 12, 2020 05:27

var (
eventSignatures = []string{
"BatchCreated(bytes32,uint256,address,uint256)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depth is now uint8

eventSignatures = []string{
"BatchCreated(bytes32,uint256,address,uint256)",
"BatchTopUp(bytes32,uint256)",
"BatchDepthIncrease(bytes32,uint256",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here about depth. also missing )


// parse reifies the event log type as a struct
// weakly unsafe in that if there is another event, nil is returned
func parse(log types.Log) postage.Event {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this approach does not work as some event parameters are indexed (only appears as topics, not events). see this for reference: https://github.com/ethereum/go-ethereum/blob/master/accounts/abi/bind/base.go#L350.


// parse reifies the event log type as a struct
// weakly unsafe in that if there is another event, nil is returned
func parse(log types.Log) postage.Event {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the very least we must check for Removed here. Otherwise not only are we not going to catch the reorganisation, we'll apply the removed event twice.

Copy link
Member

@ralph-pichler ralph-pichler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the tests you can just create instances of types.Log with the right topics (like here #934, except with the real topics if you want to test the parse function).

Reorg handling will be tricky. Functions here which take the block number should at least also take the block hash as the same block number later might refer to a different block but block hashes never change.
Another important point to consider is that if the socket connection to the client breaks and we open a new subscription from the last block we processed we will not get Removed events even in case of reorgs of events still received on the old subscription. This will lead to an inconsistent batch database. The same applies on bee restarts for blocks which were already processed but reorganised during the down time.

Copy link
Member

@ralph-pichler ralph-pichler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most solid approach to the event tracking would be to store the block hash for every block number whenever we receive a (non-removed) event through the subscription. Then on startup and whenever the subscription is remade we can check if we still agree with the node on the last processed event (by checking the block hash which also includes the receipt hash in its computation). Otherwise we can walk back through the events and find the first event that is no longer valid and revert all of the ones following it. Then we can subscribe again from the block after the last agreed event.

@zelig
Copy link
Member Author

zelig commented Nov 16, 2020

@ralph-pichler could you take over? ;)

@Eknir
Copy link
Contributor

Eknir commented Nov 30, 2020

Please attach this one to an issue. If no issue exists -- make an issue. Thanks

@acud acud force-pushed the storage-incentives branch 2 times, most recently from 134fa9a to cbd4d4a Compare December 7, 2020 15:55
@acud
Copy link
Member

acud commented Jan 11, 2021

closed in favor of #1099

@acud acud closed this Jan 11, 2021
@acud acud deleted the postage-events branch June 19, 2021 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants