Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Sep 25, 2024
1 parent 82bd6a8 commit 840fab1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
3 changes: 1 addition & 2 deletions plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ func TestPlugin(t *testing.T) {

testDB := pebble.NewMemTest(t)

// sync to integration for 2 blocks
for i := range 2 {
su, block, err := integGw.StateUpdateWithBlock(context.Background(), uint64(i))
require.NoError(t, err)
plugin.EXPECT().NewBlock(block, su, gomock.Any())
}

// sync to integration for 2 blocks
bc := blockchain.New(testDB, &utils.Integration)
synchronizer := sync.New(bc, integGw, utils.NewNopZapLogger(), 0, false).WithPlugin(plugin)

Expand Down
19 changes: 7 additions & 12 deletions sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sync
import (
"context"
"errors"
"fmt"
"runtime"
"sync/atomic"
"time"
Expand Down Expand Up @@ -193,36 +192,36 @@ func (s *Synchronizer) handlePluginRevertBlock() {
if s.plugin == nil {
return
}
block, err := s.blockchain.Head()
fromBlock, err := s.blockchain.Head()
if err != nil {
s.log.Warnw("Failed to retrieve the reverted blockchain head block for the plugin", "err", err)
return
}
stateUpdate, err := s.blockchain.StateUpdateByNumber(block.Number)
fromSU, err := s.blockchain.StateUpdateByNumber(fromBlock.Number)
if err != nil {
s.log.Warnw("Failed to retrieve the reverted blockchain head state-update for the plugin", "err", err)
return
}
reverseStateDiff, err := s.blockchain.GetReverseStateDiff()
if err != nil {
s.log.Warnw("Failed to retrieve reverse state diff", "head", block.Number, "hash", block.Hash.ShortString(), "err", err)
s.log.Warnw("Failed to retrieve reverse state diff", "head", fromBlock.Number, "hash", fromBlock.Hash.ShortString(), "err", err)
}
var toBlock *core.Block
var toSU *core.StateUpdate
if block.Number != 0 {
toBlock, err = s.blockchain.BlockByHash(block.ParentHash)
if fromBlock.Number != 0 {
toBlock, err = s.blockchain.BlockByHash(fromBlock.ParentHash)
if err != nil {
s.log.Warnw("Failed to retrieve the parent block for the plugin", "err", err)
return
}
toSU, err = s.blockchain.StateUpdateByNumber(toBlock.Number)
if err != nil {
s.log.Warnw("Failed to retrieve the parent state-update for the plugin", "err", err)
s.log.Warnw("Failed to retrieve the parents state-update for the plugin", "err", err)
return
}
}
err = (s.plugin).RevertBlock(
&junoplugin.BlockAndStateUpdate{Block: block, StateUpdate: stateUpdate},
&junoplugin.BlockAndStateUpdate{Block: fromBlock, StateUpdate: fromSU},
&junoplugin.BlockAndStateUpdate{Block: toBlock, StateUpdate: toSU},
reverseStateDiff)
if err != nil {
Expand All @@ -249,20 +248,16 @@ func (s *Synchronizer) verifierTask(ctx context.Context, block *core.Block, stat
return
}
storeTimer := time.Now()
fmt.Println("Store(blo", block.Number)
err = s.blockchain.Store(block, commitments, stateUpdate, newClasses)
fmt.Println(err)
if err != nil {
if errors.Is(err, blockchain.ErrParentDoesNotMatchHead) {
// revert the head and restart the sync process, hoping that the reorg is not deep
// if the reorg is deeper, we will end up here again and again until we fully revert reorged
// blocks
// Todo: move s.revertHead(block) before this
if s.plugin != nil {
s.handlePluginRevertBlock()
}
s.revertHead(block)

} else {
s.log.Warnw("Failed storing Block", "number", block.Number,
"hash", block.Hash.ShortString(), "err", err)
Expand Down

0 comments on commit 840fab1

Please sign in to comment.