Skip to content

Commit

Permalink
chore: hardcode most recent ethereum block height for patch upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Letang <[email protected]>
  • Loading branch information
jeremyletang authored and EVODelavega committed Mar 27, 2024
1 parent f1e8d98 commit fb4964d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
17 changes: 13 additions & 4 deletions core/datasource/external/ethverifier/verifier_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,16 @@ func (s *Verifier) LoadState(ctx context.Context, payload *types.Payload) ([]typ
return nil, nil
case *types.PayloadEthOracleLastBlock:
lastEthBlock := pl.EthOracleLastBlock
if vgcontext.InProgressUpgradeFrom(ctx, "v0.74.9") {
blockHeight, err := vgcontext.BlockHeightFromContext(ctx)
if err != nil {
s.log.Panic("issue extracting block from context", logging.Error(err))
}
if blockHeight == 41090047 {
s.log.Info("update eth block on patch", logging.Uint64("height", blockHeight))
// use a recent time instead here to skip unneeded blocks
lastEthBlock = &types.EthBlock{
Height: 19384217,
Time: 1709825615,
Height: 19525606,
Time: 1711541891,
}
}

Expand All @@ -177,7 +182,11 @@ func (s *Verifier) LoadState(ctx context.Context, payload *types.Payload) ([]typ

func (s *Verifier) OnStateLoaded(ctx context.Context) error {
// ensure patch block is set to lastBlock
if vgcontext.InProgressUpgradeFrom(ctx, "v0.74.9") {
blockHeight, err := vgcontext.BlockHeightFromContext(ctx)
if err != nil {
s.log.Panic("issue extracting block from context", logging.Error(err))
}
if blockHeight == 41090047 {
s.patchBlock = s.lastBlock
}

Expand Down
20 changes: 11 additions & 9 deletions core/datasource/external/ethverifier/verifier_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ func TestEthereumOracleVerifierSnapshotEmpty(t *testing.T) {
restoredVerifier := getTestEthereumOracleVerifier(t)
defer restoredVerifier.ctrl.Finish()

_, err = restoredVerifier.LoadState(context.Background(), types.PayloadFromProto(snap))
ctx := vgcontext.WithBlockHeight(context.Background(), 123)
_, err = restoredVerifier.LoadState(ctx, types.PayloadFromProto(snap))
require.Nil(t, err)
_, err = restoredVerifier.LoadState(context.Background(), types.PayloadFromProto(slbsnap))
_, err = restoredVerifier.LoadState(ctx, types.PayloadFromProto(slbsnap))
require.Nil(t, err)

restoredVerifier.ethCallEngine.EXPECT().Start()

// As the verifier has no state, the call engine should not have its last block set.
restoredVerifier.OnStateLoaded(context.Background())
restoredVerifier.OnStateLoaded(ctx)
}

func TestEthereumOracleVerifierWithPendingQueryResults(t *testing.T) {
Expand Down Expand Up @@ -158,16 +159,17 @@ func TestEthereumOracleVerifierWithPendingQueryResults(t *testing.T) {
restoredVerifier.ts.EXPECT().GetTimeNow().AnyTimes()
restoredVerifier.witness.EXPECT().RestoreResource(gomock.Any(), gomock.Any()).Times(1)

_, err = restoredVerifier.LoadState(context.Background(), types.PayloadFromProto(snap))
ctx := vgcontext.WithBlockHeight(context.Background(), 123)
_, err = restoredVerifier.LoadState(ctx, types.PayloadFromProto(snap))
require.Nil(t, err)
_, err = restoredVerifier.LoadState(context.Background(), types.PayloadFromProto(slbsnap))
_, err = restoredVerifier.LoadState(ctx, types.PayloadFromProto(slbsnap))
require.Nil(t, err)
_, err = restoredVerifier.LoadState(context.Background(), types.PayloadFromProto(miscState))
_, err = restoredVerifier.LoadState(ctx, types.PayloadFromProto(miscState))
require.Nil(t, err)

// After the state of the verifier is loaded it should start the call engine at the restored height
restoredVerifier.ethCallEngine.EXPECT().StartAtHeight(uint64(5), uint64(100))
restoredVerifier.OnStateLoaded(context.Background())
restoredVerifier.OnStateLoaded(ctx)

// Check its there by adding it again and checking for duplication error
require.ErrorIs(t, errors.ErrDuplicatedEthereumCallEvent, restoredVerifier.ProcessEthereumContractCallResult(callEvent))
Expand All @@ -192,7 +194,7 @@ func TestEthereumVerifierPatchBlock(t *testing.T) {
assert.NoError(t, checkResult)

// now we want to restore as if we are doing an upgrade
ctx := vgcontext.WithSnapshotInfo(context.Background(), "v0.74.9", true)
ctx := vgcontext.WithBlockHeight(context.Background(), 41090047)

lb, _, err := eov.GetState(lastEthBlockKey)
require.Nil(t, err)
Expand Down Expand Up @@ -234,7 +236,7 @@ func TestEthereumVerifierPatchBlock(t *testing.T) {
assert.NoError(t, checkResult)

// restore from the snapshot not at upgrade height
ctx = context.Background()
ctx = vgcontext.WithBlockHeight(context.Background(), 1234)
lb, _, err = restoredVerifier.GetState(lastEthBlockKey)
require.Nil(t, err)
require.NotNil(t, lb)
Expand Down

0 comments on commit fb4964d

Please sign in to comment.