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

Architecture improvement: isolate DB access to the Sentry #78

Closed
22 tasks done
Ivshti opened this issue Mar 16, 2019 · 2 comments
Closed
22 tasks done

Architecture improvement: isolate DB access to the Sentry #78

Ivshti opened this issue Mar 16, 2019 · 2 comments
Assignees
Milestone

Comments

@Ivshti
Copy link
Member

Ivshti commented Mar 16, 2019

possibly replaces the need of #31

The proposal is to change the architecture in the following way:

  • The Sentry is the only component that has a connection to the database
  • The worker ticks are refactored into pure, testable functions
  • The worker executable (bin/validatorWorker) would retrieve the latest messages from the Sentry, the latest event aggregates, and produce new message (either NewState, ApproveState/InvalidNewState) and submit it back to the Sentry (actually, propagates the messages to everyone)

There are a bunch of benefits:

  • Replaces DB abstraction #31 and allows us to swap out the DB more easily
  • Allows easier testability by testing the follower/leader tick pure functions
  • Security: before producing a new state, we'd always validate the previous one and whether we signed it; DB tampering becomes less of an issue

This, however, also requires dropping the Watcher. Instead, that functionality would be moved to the adapter. When a channel is submitted, the adapter will check if it's admissible. For Ethereum, this would mean that the channel is submitted on-chain. This also has the advantage of immediate feedback.

In order to still preserve the ability for end-users to submit channels without waiting for them to be submitted on-chain, we can implement a submission API in the Market or more appropriately the Relayer that would try to submit the channel to the validator, after it's on-chain.

Another possible issue is that there's no API to submit the full tree in the Sentry. However, we can introduce an Accounting message type to do the same. In order to optimize this for storage/performance in the future, we can purge the tree for the older states.


TODO:

  • adapter.sign should ensure replay protection itself; see Heartbeat - getSignableStateRoot does this exact thing
  • REFACTOR: validator msgs: sequential ID?
  • REFACTOR: /last-approved/ method on the sentry AND tests
  • REFACTOR: newState: should only use balances
  • REFACTOR: drop isValidValidatorFees; this check is pointless, since ultimately we're signing and enforcing OUTPACE/health on balancesAfterFees; so if you want to deceive the follower, you can always forge a preimage of balancesAfterFees which will pass the check; in other words, nothing really depends on the balances before fees (in NewState/ApproveState), so no point in enforcing it
  • API: should we wrap validator messages in msg? we lose from and received: decision: yes, we lose nothing from having that
  • sentry interface, in place of the propagation lib
  • drop nothingNew - ticks would be ran every time
  • drop stateTree
  • make everything work
  • accounting: { lastEvAggr, balancesBeforeFees, balances }
  • InvalidNewState should be emitted only once; so ticks should happen only if there is no OUR msg with that stateRoot
  • test: we only respond to a new NewState once
  • read through the doc/pseudocode and see if we missed anything
  • decide on purging/cleanup logic

and some tests improvement in a separate PR:

  • test: DRY, async/await
  • test: no NewStates are being produced when we just trigger the tick
  • test: invalid transition
  • test: propagation works
@Ivshti Ivshti added this to the v0.4 milestone Mar 16, 2019
@samparsky
Copy link
Contributor

Use async / await syntax #77 for the refactoring

@Ivshti
Copy link
Member Author

Ivshti commented Mar 26, 2019

done with the merge of #88

@Ivshti Ivshti closed this as completed Mar 26, 2019
@Ivshti Ivshti unpinned this issue Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants