Skip to content

Commit

Permalink
Merge pull request #39 from gnosischain/fix/erigon-td-remove
Browse files Browse the repository at this point in the history
Mocked SetTTDBlockClient function for Erigon
  • Loading branch information
brbrr authored Sep 9, 2024
2 parents d327e56 + 3c70684 commit 88746f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
33 changes: 17 additions & 16 deletions simulators/ethereum/engine-gnosis-erigon/clmock/clmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/sha256"
"encoding/binary"
"encoding/json"
"fmt"
"math/big"
"math/rand"
Expand Down Expand Up @@ -274,21 +273,23 @@ func (cl *CLMocker) SetTTDBlockClient(ec client.EngineClient) {
}
cl.HeaderHistory[cl.LatestHeader.Number.Uint64()] = &cl.LatestHeader.Header

ctx, cancel = context.WithTimeout(cl.TestContext, globals.RPCTimeout)
defer cancel()

if td, err := ec.GetTotalDifficulty(ctx); err != nil {
cl.Fatalf("CLMocker: Error getting total difficulty from engine client: %v", err)
panic(err)
} else if td.Cmp(ec.TerminalTotalDifficulty()) < 0 {
cl.Fatalf("CLMocker: Attempted to set TTD Block when TTD had not been reached: %d > %d", ec.TerminalTotalDifficulty(), td)
panic(err)
} else {
cl.Logf("CLMocker: TTD has been reached at block %d (%d>=%d)\n", cl.LatestHeader.Number, td, ec.TerminalTotalDifficulty())
jsH, _ := json.MarshalIndent(cl.LatestHeader, "", " ")
cl.Logf("CLMocker: Client: %s, Block %d: %s\n", ec.ID(), cl.LatestHeader.Number, jsH)
cl.ChainTotalDifficulty = td
}
// ctx, cancel = context.WithTimeout(cl.TestContext, globals.RPCTimeout)
// defer cancel()

// TODO: Commented TotalDifficulty related things to remove it in the future

// if td, err := ec.GetTotalDifficulty(ctx); err != nil {
// cl.Fatalf("CLMocker: Error getting total difficulty from engine client: %v", err)
// panic(err)
// } else if td.Cmp(ec.TerminalTotalDifficulty()) < 0 {
// cl.Fatalf("CLMocker: Attempted to set TTD Block when TTD had not been reached: %d > %d", ec.TerminalTotalDifficulty(), td)
// panic(err)
// } else {
// cl.Logf("CLMocker: TTD has been reached at block %d (%d>=%d)\n", cl.LatestHeader.Number, td, ec.TerminalTotalDifficulty())
// jsH, _ := json.MarshalIndent(cl.LatestHeader, "", " ")
// cl.Logf("CLMocker: Client: %s, Block %d: %s\n", ec.ID(), cl.LatestHeader.Number, jsH)
// cl.ChainTotalDifficulty = td
// }

cl.TTDReached = true

Expand Down
8 changes: 5 additions & 3 deletions simulators/ethereum/engine-gnosis-erigon/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,14 @@ func WaitForTTD(ec client.EngineClient, wg *sync.WaitGroup, done chan<- WaitTTDR
for {
select {
case <-time.After(TTDCheckPeriod):
ttdReached, err := CheckTTD(ec, ctx)
if err == nil && ttdReached {
// ttdReached, err := CheckTTD(ec, ctx)
// TODO: Remove WaitForTTD in the future
ttdReached := true
if ttdReached {
select {
case done <- WaitTTDResponse{
ec: ec,
err: err,
err: nil,
}:
case <-ctx.Done():
}
Expand Down

0 comments on commit 88746f1

Please sign in to comment.