diff --git a/beacon-chain/cache/payload_id.go b/beacon-chain/cache/payload_id.go index feda4c606..930a4fbe6 100644 --- a/beacon-chain/cache/payload_id.go +++ b/beacon-chain/cache/payload_id.go @@ -1,6 +1,7 @@ package cache import ( + "bytes" "sync" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" @@ -49,14 +50,15 @@ func (f *ProposerPayloadIDsCache) SetProposerAndPayloadIDs(slot types.Slot, vId var vIdBytes [vIdLength]byte copy(vIdBytes[:], bytesutil.Uint64ToBytesBigEndian(uint64(vId))) - var bytes [vpIdsLength]byte - copy(bytes[:], append(vIdBytes[:], pId[:]...)) + var bs [vpIdsLength]byte + copy(bs[:], append(vIdBytes[:], pId[:]...)) - _, ok := f.slotToProposerAndPayloadIDs[slot] - // Ok to overwrite if the slot is already set but the payload ID is not set. - // This combats the re-org case where payload assignment could change the epoch of. - if !ok || (ok && pId != [pIdLength]byte{}) { - f.slotToProposerAndPayloadIDs[slot] = bytes + ids, ok := f.slotToProposerAndPayloadIDs[slot] + // Ok to overwrite if the slot is already set but the cached payload ID is not set. + // This combats the re-org case where payload assignment could change at the start of the epoch. + byte8 := [vIdLength]byte{} + if !ok || (ok && bytes.Equal(ids[vIdLength:], byte8[:])) { + f.slotToProposerAndPayloadIDs[slot] = bs } } diff --git a/beacon-chain/cache/payload_id_test.go b/beacon-chain/cache/payload_id_test.go index 7d40e3dad..266cda283 100644 --- a/beacon-chain/cache/payload_id_test.go +++ b/beacon-chain/cache/payload_id_test.go @@ -41,7 +41,7 @@ func TestValidatorPayloadIDsCache_GetAndSaveValidatorPayloadIDs(t *testing.T) { require.Equal(t, vid, i) require.Equal(t, pid, p) - // reset cache with existing pid + // existing pid - no change in cache slot = types.Slot(9456456) vid = types.ValidatorIndex(11111) newPid := [8]byte{1, 2, 3, 33, 72, 8, 7, 1} @@ -49,7 +49,7 @@ func TestValidatorPayloadIDsCache_GetAndSaveValidatorPayloadIDs(t *testing.T) { i, p, ok = cache.GetProposerPayloadIDs(slot) require.Equal(t, true, ok) require.Equal(t, vid, i) - require.Equal(t, newPid, p) + require.Equal(t, pid, p) // remove cache entry cache.PrunePayloadIDs(slot + 1)