Verify roblobs (#13245)

* scaffolding for verification package

* WIP blob verification methods

* lock wrapper for safer forkchoice sharing

* more solid cache and verification designs; adding tests

* more test coverage, adding missing cache files

* clearer func name

* remove forkchoice borrower (it's in another PR)

* revert temporary interface experiment

* lint

* nishant feedback

* add comments with spec text to all verifications

* some comments on public methods

* invert confusing verification name

* deep source

* remove cache from ProposerCache + gaz

* more consistently early return on error paths

* messed up the test with the wrong config value

* terence naming feedback

* tests on BeginsAt

* lint

* deep source...

* name errors after failure, not expectation

* deep sooource

* check len()==0 instead of nil so empty lists work

* update test for EIP-7044

---------

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
This commit is contained in:
kasey
2023-12-06 20:36:25 -06:00
committed by GitHub
parent 4e4fb9ad52
commit 4008ea736f
26 changed files with 1723 additions and 66 deletions

View File

@@ -163,6 +163,12 @@ func ToTime(genesisTimeSec uint64, slot primitives.Slot) (time.Time, error) {
return time.Unix(int64(sTime), 0), nil // lint:ignore uintcast -- A timestamp will not exceed int64 in your lifetime.
}
// BeginsAt computes the timestamp where the given slot begins, relative to the genesis timestamp.
func BeginsAt(slot primitives.Slot, genesis time.Time) time.Time {
sd := time.Second * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Duration(slot)
return genesis.Add(sd)
}
// Since computes the number of time slots that have occurred since the given timestamp.
func Since(time time.Time) primitives.Slot {
return CurrentSlot(uint64(time.Unix()))

View File

@@ -153,6 +153,37 @@ func TestEpochStartSlot_OK(t *testing.T) {
}
}
func TestBeginsAtOK(t *testing.T) {
cases := []struct {
name string
genesis int64
slot primitives.Slot
slotTime time.Time
}{
{
name: "genesis",
slotTime: time.Unix(0, 0),
},
{
name: "slot 1",
slot: 1,
slotTime: time.Unix(int64(params.BeaconConfig().SecondsPerSlot), 0),
},
{
name: "slot 1",
slot: 32,
slotTime: time.Unix(int64(params.BeaconConfig().SecondsPerSlot)*32, 0),
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
genesis := time.Unix(c.genesis, 0)
st := BeginsAt(c.slot, genesis)
require.Equal(t, c.slotTime, st)
})
}
}
func TestEpochEndSlot_OK(t *testing.T) {
tests := []struct {
epoch primitives.Epoch