From fb4964db68f4f3aeec900336cdb37dc903db88fd Mon Sep 17 00:00:00 2001 From: Jeremy Letang Date: Wed, 27 Mar 2024 13:20:07 +0100 Subject: [PATCH] chore: hardcode most recent ethereum block height for patch upgrade Signed-off-by: Jeremy Letang --- .../external/ethverifier/verifier_snapshot.go | 17 ++++++++++++---- .../ethverifier/verifier_snapshot_test.go | 20 ++++++++++--------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/core/datasource/external/ethverifier/verifier_snapshot.go b/core/datasource/external/ethverifier/verifier_snapshot.go index 02d0ec1a786..35be947dfba 100644 --- a/core/datasource/external/ethverifier/verifier_snapshot.go +++ b/core/datasource/external/ethverifier/verifier_snapshot.go @@ -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, } } @@ -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 } diff --git a/core/datasource/external/ethverifier/verifier_snapshot_test.go b/core/datasource/external/ethverifier/verifier_snapshot_test.go index 9d852477a60..1f8d3da282b 100644 --- a/core/datasource/external/ethverifier/verifier_snapshot_test.go +++ b/core/datasource/external/ethverifier/verifier_snapshot_test.go @@ -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) { @@ -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)) @@ -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) @@ -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)