Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyilong committed Mar 21, 2023
1 parent 8c18949 commit 3bf17c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ledger/execution/tx_validator_set_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (exec *SubchainValidatorSetUpdateTxExecutor) process(chainID string, view *
}

if currentDynasty.Cmp(common.Big0) == 0 {
// special handling: the node just loaded the genesis snapshot, we should trust the initial ValidatorSet specified by the snapshot
// special handling: currentDynasty is 0 means the node just loaded the genesis snapshot, we should trust the initial ValidatorSet specified by the snapshot
validatorSetSpecifiedInTheSnapshot := view.GetValidatorSet()

logger.Debugf("currentDynasty: %v", currentDynasty)
Expand Down
12 changes: 8 additions & 4 deletions ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,15 @@ func (ledger *Ledger) getNewDynastyAndValidatorSet(view *slst.StoreView) (enteri
logger.Debugf("currentDynasty: %v, witnessedDynasty: %v, egistrationDynasty: %v, registrationMainchainHeight: %v", currentDynasty, witnessedDynasty, registrationDynasty, registrationMainchainHeight)

if witnessedDynasty.Cmp(registrationDynasty) == 0 {
// For the initial dynasty, i.e. the dynasty during which the subchain was registered, instead of querying
// the validator set from the main chain, we trust the validator set in the snapshot
if currentDynasty.Cmp(common.Big0) == 0 { // the first validator set update
return true, witnessedDynasty, view.GetValidatorSet() // the validator set specified in the snapshot
// Specicial case: When the node is in the dynasty where the subchain was registered. The subchain should use the ValidatorSet
// specified in the snapshot (in stead of querying the main chain). Yet, the node needs to update the dynasty
// in the ViewStore to witnessedDynasty if witnessedDynasty is not 0

if witnessedDynasty.Cmp(common.Big0) != 0 && currentDynasty.Cmp(common.Big0) == 0 { // the first validator set update
// update the dynast to witnessedDynasty, and continue to use the validator set specified in the snapshot
return true, witnessedDynasty, view.GetValidatorSet()
} else {
// witnessedDynasty is 0, so no update is needed, continue to use the ValidatorSet loaded from the snapshot
return false, nil, nil
}
}
Expand Down

0 comments on commit 3bf17c9

Please sign in to comment.