fixing builder version check (#15568)

* adding fix

* fixing test
This commit is contained in:
james-prysm
2025-08-07 20:42:55 -05:00
committed by GitHub
parent fe000e5629
commit 2ec5914b4a
3 changed files with 89 additions and 67 deletions

View File

@@ -18,6 +18,7 @@ import (
"github.com/OffchainLabs/prysm/v6/encoding/ssz"
"github.com/OffchainLabs/prysm/v6/monitoring/tracing"
"github.com/OffchainLabs/prysm/v6/monitoring/tracing/trace"
"github.com/OffchainLabs/prysm/v6/network/forks"
enginev1 "github.com/OffchainLabs/prysm/v6/proto/engine/v1"
"github.com/OffchainLabs/prysm/v6/runtime/version"
"github.com/OffchainLabs/prysm/v6/time/slots"
@@ -219,9 +220,16 @@ func (vs *Server) getPayloadHeaderFromBuilder(
return nil, errors.New("builder returned nil bid")
}
bidVersion := signedBid.Version()
headBlockVersion := b.Version()
if !isVersionCompatible(bidVersion, headBlockVersion) {
return nil, fmt.Errorf("builder bid response version: %d is not compatible with head block version: %d for epoch %d", bidVersion, headBlockVersion, slots.ToEpoch(slot))
fork, err := forks.Fork(slots.ToEpoch(slot))
if err != nil {
return nil, errors.Wrap(err, "unable to get fork information")
}
forkVersion, ok := params.ConfigForkVersions(params.BeaconConfig())[bytesutil.ToBytes4(fork.CurrentVersion)]
if !ok {
return nil, errors.New("unable to find current fork in schedule")
}
if !isVersionCompatible(bidVersion, forkVersion) {
return nil, fmt.Errorf("builder bid response version: %d is not compatible with expected version: %d for epoch %d", bidVersion, forkVersion, slots.ToEpoch(slot))
}
bid, err := signedBid.Message()

View File

@@ -873,6 +873,7 @@ func TestServer_getPayloadHeader(t *testing.T) {
err string
returnedHeader *v1.ExecutionPayloadHeader
returnedHeaderCapella *v1.ExecutionPayloadHeaderCapella
forkVersion int
}{
{
name: "can't request before bellatrix epoch",
@@ -974,7 +975,7 @@ func TestServer_getPayloadHeader(t *testing.T) {
return wb
}(),
},
err: "builder bid response version: 3 is not compatible with head block version: 2 for epoch 1",
err: "builder bid response version: 3 is not compatible with expected version: 2 for epoch 1",
},
{
name: "different bid version during hard fork",
@@ -1085,10 +1086,21 @@ func TestServer_getPayloadHeader(t *testing.T) {
}(),
},
// Should succeed because Electra bids are compatible with Fulu head blocks
forkVersion: version.Fulu,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if tc.forkVersion != 0 {
params.SetupTestConfigCleanup(t)
cfg := params.BeaconConfig()
if tc.forkVersion == version.Fulu {
cfg.FuluForkEpoch = 0
cfg.BellatrixForkEpoch = 0
cfg.InitializeForkSchedule()
}
params.OverrideBeaconConfig(cfg)
}
vs := &Server{BeaconDB: dbTest.SetupDB(t), BlockBuilder: tc.mock, HeadFetcher: tc.fetcher, TimeFetcher: &blockchainTest.ChainService{
Genesis: genesis,
}}
@@ -1305,104 +1317,103 @@ func Test_expectedGasLimit(t *testing.T) {
}
func TestIsVersionCompatible(t *testing.T) {
tests := []struct {
name string
bidVersion int
headBlockVersion int
want bool
name string
bidVersion int
currentForkVersion int
want bool
}{
{
name: "Exact version match - Bellatrix",
bidVersion: version.Bellatrix,
headBlockVersion: version.Bellatrix,
want: true,
name: "Exact version match - Bellatrix",
bidVersion: version.Bellatrix,
currentForkVersion: version.Bellatrix,
want: true,
},
{
name: "Exact version match - Capella",
bidVersion: version.Capella,
headBlockVersion: version.Capella,
want: true,
name: "Exact version match - Capella",
bidVersion: version.Capella,
currentForkVersion: version.Capella,
want: true,
},
{
name: "Exact version match - Deneb",
bidVersion: version.Deneb,
headBlockVersion: version.Deneb,
want: true,
name: "Exact version match - Deneb",
bidVersion: version.Deneb,
currentForkVersion: version.Deneb,
want: true,
},
{
name: "Exact version match - Electra",
bidVersion: version.Electra,
headBlockVersion: version.Electra,
want: true,
name: "Exact version match - Electra",
bidVersion: version.Electra,
currentForkVersion: version.Electra,
want: true,
},
{
name: "Exact version match - Fulu",
bidVersion: version.Fulu,
headBlockVersion: version.Fulu,
want: true,
name: "Exact version match - Fulu",
bidVersion: version.Fulu,
currentForkVersion: version.Fulu,
want: true,
},
{
name: "Electra bid with Fulu head block - Compatible",
bidVersion: version.Electra,
headBlockVersion: version.Fulu,
want: true,
name: "Electra bid with Fulu head block - Compatible",
bidVersion: version.Electra,
currentForkVersion: version.Fulu,
want: true,
},
{
name: "Fulu bid with Electra head block - Not compatible",
bidVersion: version.Fulu,
headBlockVersion: version.Electra,
want: false,
name: "Fulu bid with Electra head block - Not compatible",
bidVersion: version.Fulu,
currentForkVersion: version.Electra,
want: false,
},
{
name: "Deneb bid with Electra head block - Not compatible",
bidVersion: version.Deneb,
headBlockVersion: version.Electra,
want: false,
name: "Deneb bid with Electra head block - Not compatible",
bidVersion: version.Deneb,
currentForkVersion: version.Electra,
want: false,
},
{
name: "Electra bid with Deneb head block - Not compatible",
bidVersion: version.Electra,
headBlockVersion: version.Deneb,
want: false,
name: "Electra bid with Deneb head block - Not compatible",
bidVersion: version.Electra,
currentForkVersion: version.Deneb,
want: false,
},
{
name: "Capella bid with Deneb head block - Not compatible",
bidVersion: version.Capella,
headBlockVersion: version.Deneb,
want: false,
name: "Capella bid with Deneb head block - Not compatible",
bidVersion: version.Capella,
currentForkVersion: version.Deneb,
want: false,
},
{
name: "Bellatrix bid with Capella head block - Not compatible",
bidVersion: version.Bellatrix,
headBlockVersion: version.Capella,
want: false,
name: "Bellatrix bid with Capella head block - Not compatible",
bidVersion: version.Bellatrix,
currentForkVersion: version.Capella,
want: false,
},
{
name: "Phase0 bid with Altair head block - Not compatible",
bidVersion: version.Phase0,
headBlockVersion: version.Altair,
want: false,
name: "Phase0 bid with Altair head block - Not compatible",
bidVersion: version.Phase0,
currentForkVersion: version.Altair,
want: false,
},
{
name: "Deneb bid with Fulu head block - Not compatible",
bidVersion: version.Deneb,
headBlockVersion: version.Fulu,
want: false,
name: "Deneb bid with Fulu head block - Not compatible",
bidVersion: version.Deneb,
currentForkVersion: version.Fulu,
want: false,
},
{
name: "Capella bid with Fulu head block - Not compatible",
bidVersion: version.Capella,
headBlockVersion: version.Fulu,
want: false,
name: "Capella bid with Fulu head block - Not compatible",
bidVersion: version.Capella,
currentForkVersion: version.Fulu,
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := isVersionCompatible(tt.bidVersion, tt.headBlockVersion)
got := isVersionCompatible(tt.bidVersion, tt.currentForkVersion)
if got != tt.want {
t.Errorf("isVersionCompatible(%d, %d) = %v, want %v", tt.bidVersion, tt.headBlockVersion, got, tt.want)
t.Errorf("isVersionCompatible(%d, %d) = %v, want %v", tt.bidVersion, tt.currentForkVersion, got, tt.want)
}
})
}

View File

@@ -0,0 +1,3 @@
### Fixed
- builder version check was using head block version instead of current fork's version based on slot, fixes e2e from https://github.com/OffchainLabs/prysm/commit/57e27199bdb9b3ef1af14c3374999aba5e0788a3.