-
Notifications
You must be signed in to change notification settings - Fork 17
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
Updated ETHDKG with new flow and contract bindings #66
Conversation
…dators registrater
- Fixed ShouldRetry logic on tasks - ETHDKG can now be restarted - Improved RetrieveParticipants to be faster and more efficient
…pulling data from the chain - Improved scheduling management in regards to ShouldRetry logic that now relies on start and end blocks set when the task is created - Fixed bug where evicting a validator would cause access out of array boundaries due to poor state management - Cleanups
- Fixed base genesis file to support london fork - Improved code reusability on registration (NeedsRegistration)
- Fixed registration check
…ncluding a task, to avoid race conditions on ethereum forks
- Improved WaitConfirmations() method to use eth.GetFinalityDelay()
… to test it properly - Improved testing structure for better state management and keeping DRY tests - Tested bad distributed shares
…issing key shares and mpk submission
done = true | ||
} | ||
|
||
time.Sleep(5 * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code smell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be addressed and fixed in the following ticket: https://madhive.atlassian.net/browse/MP-299
blockchain/monitor/event_setup.go
Outdated
@@ -13,43 +13,72 @@ import ( | |||
func SetupEventMap(em *objects.EventMap, cdb *db.Database, adminHandler interfaces.AdminHandler, depositHandler interfaces.DepositHandler) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not hardcode the event hashes as this will result in silent failure when an event is updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parse from bindings
if err != nil { | ||
return err | ||
} | ||
|
||
epoch := uint32(event.Epoch.Int64()) | ||
|
||
index := uint8(event.Index.Uint64()) - 1 | ||
index := uint32(event.Index.Uint64()) // - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean up how this index is used below
if err != nil { | ||
return err | ||
} | ||
// err = checkValidatorSet(state, epoch, logger, adminHandler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove, not used here
blockchain/monitor/monitor.go
Outdated
logger.WithField("EventID", eventID). | ||
WithField("info", info.Name). | ||
Info("event received") | ||
} /* else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean up
} | ||
|
||
// GetSortedParticipants returns the participant list sorted by Index field | ||
func (state *DkgState) GetSortedParticipants() ParticipantList { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to make sure this has state.lock/unlock where used, see previous state locking comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for functions below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -66,7 +67,7 @@ func (registry *TypeRegistry) WrapInstance(t interface{}) (*InstanceWrapper, err | |||
|
|||
name, present := registry.lookupName(tipe) | |||
if !present { | |||
return nil, ErrUnknownType | |||
return nil, fmt.Errorf("unable to wrapInstance: %v", tipe) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
evaluate if panic would be better here
blockchain/objects/scheduler_test.go
Outdated
t.Log("error:", err) | ||
assert.NotNil(t, err) | ||
|
||
// _, err = s.Schedule(6, 14, task) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean up
|
||
// These are the valid phases of ETHDKG | ||
const ( | ||
Registration EthDKGPhase = iota | ||
RegistrationOpen EthDKGPhase = iota |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iota + 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
force default value is invalid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
! investigate, if necessary preserve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get through the bindings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bindings don't give us this information yet ethereum/EIPs#47
blockchain/transaction_queue.go
Outdated
@@ -146,6 +146,12 @@ func (b *Behind) collectReceipts() { | |||
b.logger.Debugf("receipt not found: %v", txn.Hex()) | |||
return | |||
} | |||
|
|||
//This only could happen using a SimulatedBackend during the tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build tag?
cmd/deploy/deploy.go
Outdated
} | ||
eu := &blockchain.Updater{Updater: ethdkgUpdater, TxnOpts: txnOpts, Logger: logger} | ||
eth.Queue().QueueGroupTransaction(ctx, MIGRATION_GRP, eu.Add("migrate(uint256,uint32,uint32,uint256[4],address[],uint256[4][])", migrateEthDKGAddr)) | ||
// // Wire EthDKG migration contract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean up
cmd/utils/utils.go
Outdated
@@ -252,8 +264,13 @@ func register(logger *logrus.Entry, eth interfaces.Ethereum, cmd *cobra.Command, | |||
|
|||
// More ethereum setup | |||
acct := eth.GetDefaultAccount() | |||
|
|||
if acct.Address.String() == "0x546F99F244b7B58B855330AE0E2BC1b30b41302F" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no magic values / hardcoded addresses
logger.Errorf("StakingToken.Approve() failed") | ||
var retry bool = true | ||
for retry { | ||
txn, err := c.StakingToken().Approve(txnOpts, c.ValidatorsAddress(), big.NewInt(1_000_000)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no magic values, resolve from contracts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is going to be deleted soon because we'll be using the StakeNFT contract for this logic
logger.Errorf("Staking.LockStake() failed") | ||
retry = true | ||
for retry { | ||
txn, err := c.Staking().LockStake(txnOpts, big.NewInt(1_000_000)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is going to be deleted soon because we'll be using the StakeNFT contract for this logic
cmd/utils/utils.go
Outdated
} | ||
if rcpt != nil && rcpt.Status != 1 { | ||
logger.Errorf("StakingToken.Approve() failed") | ||
var retry bool = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bound these for-loops
cmd/utils/utils.go
Outdated
@@ -485,6 +516,82 @@ func deposittokens(logger *logrus.Entry, eth interfaces.Ethereum, cmd *cobra.Com | |||
return 0 | |||
} | |||
|
|||
func testtx(logger *logrus.Entry, eth interfaces.Ethereum, cmd *cobra.Command, args []string) int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is scary
cmd/utils/utils.go
Outdated
@@ -581,17 +688,10 @@ func ethdkg(logger *logrus.Entry, eth interfaces.Ethereum, cmd *cobra.Command, a | |||
|
|||
for _, log := range logs { | |||
if log.Topics[0].Hex() == "0x9c6f8368fe7e77e8cb9438744581403bcb3f53298e517f04c1b8475487402e97" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove magic values
// If we aren't registered correctly retry won't work -- Not true for registration | ||
if status == NoRegistration || status == BadRegistration { | ||
logger.Warnf("registration status: %v", status) | ||
if currentBlock >= expectedLastBlock || currentBlock < expectedFirstBlock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oddity around expectedFirstBlock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
investigate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See and evaluate comments, make tickets as necessary. Fix only required comments for merge.
Kudos, SonarCloud Quality Gate passed! |
Scope
What is changing with this PR?
This PR introduces improvements to the ETHDKG flow enabling it to execute faster on good conditions, as well as leverage the new smart contracts' logic. It also introduces improvements in state management, retry logics, scheduling of tasks, and a great deal of testing. This new ETHDKG flow is event driven and allows for the process to complete quicker than before, with less phases to go through, and achieves greater code coverage.
Why?
Why are we doing this?
We're doing this to simplify the existing flow, speed up the process and integrate with the latest and greatest ETHDKG smart contracts.
Follow up stories
If any, what are the follow-up tasks required other than merging this PR? Have they been arranged?