Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocked SetTTDBlockClient function for Erigon #39

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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