Skip to content

Commit

Permalink
Merge pull request OffchainLabs#2483 from OffchainLabs/batch-confirma…
Browse files Browse the repository at this point in the history
…tions-on-migration

Batch validator confirmations when nitro migration begins
  • Loading branch information
PlasmaPower authored Aug 31, 2022
2 parents bdde908 + 76dba52 commit 306c67d
Show file tree
Hide file tree
Showing 24 changed files with 1,211 additions and 70 deletions.
22 changes: 22 additions & 0 deletions packages/arb-node-core/ethbridge/rollupWatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ func (r *RollupWatcher) LookupChallengedNode(ctx context.Context, address common
return challenge.ChallengedNode, nil
}

func (r *RollupWatcher) GetNodeStakerCount(ctx context.Context, nodeNum *big.Int) (*big.Int, error) {
callOpts := r.getCallOpts(ctx)
nodeAddr, err := r.con.GetNode(callOpts, nodeNum)
if err != nil {
return nil, err
}
nodeContract, err := ethbridgecontracts.NewINode(nodeAddr, r.client)
if err != nil {
return nil, err
}
return nodeContract.StakerCount(callOpts)
}

func (r *RollupWatcher) StakerInfo(ctx context.Context, staker common.Address) (*StakerInfo, error) {
info, err := r.con.StakerMap(r.getCallOpts(ctx), staker.ToEthAddress())
if err != nil {
Expand Down Expand Up @@ -330,3 +343,12 @@ func (r *RollupWatcher) GetNode(ctx context.Context, node core.NodeID) (*NodeWat
}
return NewNodeWatcher(nodeAddress, r.client, r.baseCallOpts)
}

func (r *RollupWatcher) IsShuttingDownForNitro(ctx context.Context) (bool, error) {
shuttingDownForNitro, err := r.con.ShutdownForNitroMode(r.getCallOpts(ctx))
if err != nil {
logger.Warn().Err(err).Msg("assuming not shutting down for nitro as we failed to check")
return false, nil
}
return shuttingDownForNitro, nil
}
61 changes: 52 additions & 9 deletions packages/arb-node-core/staker/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ func (v *Validator) resolveNextNode(ctx context.Context, info *ethbridge.StakerI
if err != nil {
return err
}
latestNodeCreated, err := v.rollup.LatestNodeCreated(ctx)
if err != nil {
return err
}
shuttingDownForNitro, err := v.rollup.IsShuttingDownForNitro(ctx)
if err != nil {
return err
}
switch confirmType {
case ethbridge.CONFIRM_TYPE_INVALID:
addr := v.wallet.Address()
Expand All @@ -146,17 +154,52 @@ func (v *Validator) resolveNextNode(ctx context.Context, info *ethbridge.StakerI
logger.Info().Int("node", int(unresolvedNodeIndex.Int64())).Msg("Rejecting node")
return v.rollup.RejectNextNode(ctx, *addr)
case ethbridge.CONFIRM_TYPE_VALID:
nodeInfo, err := v.rollup.RollupWatcher.LookupNode(ctx, unresolvedNodeIndex)
if err != nil {
return err
confCount := 1
if shuttingDownForNitro {
confCount = 10
}
sendCount := new(big.Int).Sub(nodeInfo.Assertion.After.TotalSendCount, nodeInfo.Assertion.Before.TotalSendCount)
sends, err := v.lookup.GetSends(nodeInfo.Assertion.Before.TotalSendCount, sendCount)
if err != nil {
return errors.Wrap(err, "catching up to chain")
totalSendSize := 0
var lastStakerCount *big.Int
for i := 0; i < confCount && unresolvedNodeIndex.Cmp(latestNodeCreated) <= 0; i++ {
nodeInfo, err := v.rollup.RollupWatcher.LookupNode(ctx, unresolvedNodeIndex)
if err != nil {
return err
}
stakerCount, err := v.rollup.RollupWatcher.GetNodeStakerCount(ctx, unresolvedNodeIndex)
if err != nil {
return err
}
if lastStakerCount != nil {
if lastStakerCount.Cmp(stakerCount) != 0 {
logger.
Info().
Int64("stakerCount", stakerCount.Int64()).
Int64("lastStakerCount", lastStakerCount.Int64()).
Msg("not batching further confirmations as number of stakers changed")
break
}
} else {
lastStakerCount = stakerCount
}
sendCount := new(big.Int).Sub(nodeInfo.Assertion.After.TotalSendCount, nodeInfo.Assertion.Before.TotalSendCount)
sends, err := v.lookup.GetSends(nodeInfo.Assertion.Before.TotalSendCount, sendCount)
if err != nil {
return errors.Wrap(err, "catching up to chain")
}
for _, send := range sends {
totalSendSize += 32 + len(send)
}
if i > 0 && totalSendSize >= 64*1024 {
break
}
logger.Info().Int("node", int(unresolvedNodeIndex.Int64())).Msg("Confirming node")
err = v.rollup.ConfirmNextNode(ctx, nodeInfo.Assertion, sends)
if err != nil {
return err
}
unresolvedNodeIndex.Add(unresolvedNodeIndex, big.NewInt(1))
}
logger.Info().Int("node", int(unresolvedNodeIndex.Int64())).Msg("Confirming node")
return v.rollup.ConfirmNextNode(ctx, nodeInfo.Assertion, sends)
return nil
default:
return nil
}
Expand Down
66 changes: 64 additions & 2 deletions packages/arb-util/ethbridgecontracts/Bridge.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/arb-util/ethbridgecontracts/BridgeUtils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/arb-util/ethbridgecontracts/Challenge.go

Large diffs are not rendered by default.

35 changes: 2 additions & 33 deletions packages/arb-util/ethbridgecontracts/GasRefunder.go

Large diffs are not rendered by default.

33 changes: 32 additions & 1 deletion packages/arb-util/ethbridgecontracts/INode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 306c67d

Please sign in to comment.