Skip to content

Commit

Permalink
Remove global variable to change miner behaviour.
Browse files Browse the repository at this point in the history
Use a longer wait in tests for the payload to build.
  • Loading branch information
ajsutton authored and sebastianst committed Dec 14, 2023
1 parent 9cfcae8 commit d880c81
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 23 deletions.
15 changes: 7 additions & 8 deletions eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ import (
"github.com/mattn/go-colorable"
)

func init() {
miner.IsPayloadBuildingTest = true
}

var (
// testKey is a private key to use for funding a tester account.
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
Expand Down Expand Up @@ -206,8 +202,7 @@ func TestEth2PrepareAndGetPayload(t *testing.T) {
if err != nil {
t.Fatalf("error preparing payload, err=%v", err)
}
// give the payload some time to be built
time.Sleep(100 * time.Millisecond)
waitForPayloadToBuild()
payloadID := (&miner.BuildPayloadArgs{
Parent: fcState.HeadBlockHash,
Timestamp: blockParams.Timestamp,
Expand Down Expand Up @@ -639,8 +634,7 @@ func TestNewPayloadOnInvalidChain(t *testing.T) {
if resp.PayloadStatus.Status != engine.VALID {
t.Fatalf("error preparing payload, invalid status: %v", resp.PayloadStatus.Status)
}
// give the payload some time to be built
time.Sleep(50 * time.Millisecond)
waitForPayloadToBuild()
if payload, err = api.GetPayloadV1(*resp.PayloadID); err != nil {
t.Fatalf("can't get payload: %v", err)
}
Expand Down Expand Up @@ -1651,3 +1645,8 @@ func TestParentBeaconBlockRoot(t *testing.T) {
t.Fatalf("incorrect root stored: want %s, got %s", *blockParams.BeaconRoot, root)
}
}

func waitForPayloadToBuild() {
// give the payload some time to be built
time.Sleep(1 * time.Second)
}
16 changes: 2 additions & 14 deletions miner/payload_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)

var IsPayloadBuildingTest = false

// BuildPayloadArgs contains the provided parameters for building payload.
// Check engine-api specification for more details.
// https://github.com/ethereum/execution-apis/blob/main/src/engine/cancun.md#payloadattributesv3
Expand Down Expand Up @@ -98,7 +96,7 @@ type Payload struct {

err error
stopOnce sync.Once
interrupt *atomic.Int32 // interrup signal shared with worker
interrupt *atomic.Int32 // interrupt signal shared with worker
}

// newPayload initializes the payload object.
Expand Down Expand Up @@ -219,9 +217,7 @@ func (payload *Payload) stopBuilding() {
// Concurrent Resolve calls should only stop once.
payload.stopOnce.Do(func() {
log.Debug("Interrupt payload building.", "id", payload.id)
if !IsPayloadBuildingTest {
payload.interrupt.Store(commitInterruptResolve)
}
payload.interrupt.Store(commitInterruptResolve)
close(payload.stop)
})
}
Expand Down Expand Up @@ -321,14 +317,6 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
return dur
}

if IsPayloadBuildingTest {
// engine api tests assume that getPayload can be called immediately after calling
// forkchoiceUpdated. This races with closing the payload building process `stop`
// channel and setting the interrupt, so in tests we always build one full
// payload.
updatePayload()
}

var lastDuration time.Duration
for {
select {
Expand Down
1 change: 0 additions & 1 deletion miner/payload_building_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
)

func TestBuildPayload(t *testing.T) {
IsPayloadBuildingTest = true
t.Run("with-tx-pool", func(t *testing.T) { testBuildPayload(t, false) })
t.Run("no-tx-pool", func(t *testing.T) { testBuildPayload(t, true) })
}
Expand Down

0 comments on commit d880c81

Please sign in to comment.