fixup conformance tests to incorporate randomness changes
This commit is contained in:
parent
3ea3e49bdd
commit
947384041a
@ -641,9 +641,9 @@ type FullNode interface {
|
||||
// StateGetRandomnessFromBeacon is used to sample the beacon for randomness.
|
||||
StateGetRandomnessFromBeacon(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) //perm:read
|
||||
|
||||
// StateGetRandomnessFromTickets is used to sample the chain for randomness.
|
||||
// StateGetRandomnessDigestFromTickets. is used to sample the chain for randomness.
|
||||
StateGetRandomnessDigestFromTickets(ctx context.Context, randEpoch abi.ChainEpoch, tsk types.TipSetKey) (abi.Randomness, error) //perm:read
|
||||
// StateGetRandomnessFromBeacon is used to sample the beacon for randomness.
|
||||
// StateGetRandomnessDigestFromBeacon is used to sample the beacon for randomness.
|
||||
StateGetRandomnessDigestFromBeacon(ctx context.Context, randEpoch abi.ChainEpoch, tsk types.TipSetKey) (abi.Randomness, error) //perm:read
|
||||
|
||||
// StateGetBeaconEntry returns the beacon entry for the given filecoin epoch. If
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/vm"
|
||||
)
|
||||
@ -19,10 +18,10 @@ func NewFixedRand() vm.Rand {
|
||||
return &fixedRand{}
|
||||
}
|
||||
|
||||
func (r *fixedRand) GetChainRandomness(_ context.Context, _ crypto.DomainSeparationTag, _ abi.ChainEpoch, _ []byte) ([]byte, error) {
|
||||
return []byte("i_am_random_____i_am_random_____"), nil // 32 bytes.
|
||||
func (r *fixedRand) GetChainRandomness(_ context.Context, _ abi.ChainEpoch) ([32]byte, error) {
|
||||
return *(*[32]byte)([]byte("i_am_random_____i_am_random_____")), nil
|
||||
}
|
||||
|
||||
func (r *fixedRand) GetBeaconRandomness(_ context.Context, _ crypto.DomainSeparationTag, _ abi.ChainEpoch, _ []byte) ([]byte, error) {
|
||||
return []byte("i_am_random_____i_am_random_____"), nil // 32 bytes.
|
||||
func (r *fixedRand) GetBeaconRandomness(_ context.Context, _ abi.ChainEpoch) ([32]byte, error) {
|
||||
return *(*[32]byte)([]byte("i_am_random_____i_am_random_____")), nil // 32 bytes.
|
||||
}
|
||||
|
@ -8,14 +8,14 @@ import (
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/test-vectors/schema"
|
||||
|
||||
"github.com/filecoin-project/lotus/api/v0api"
|
||||
"github.com/filecoin-project/lotus/api/v1api"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/vm"
|
||||
)
|
||||
|
||||
type RecordingRand struct {
|
||||
reporter Reporter
|
||||
api v0api.FullNode
|
||||
api v1api.FullNode
|
||||
|
||||
// once guards the loading of the head tipset.
|
||||
// can be removed when https://github.com/filecoin-project/lotus/issues/4223
|
||||
@ -31,7 +31,7 @@ var _ vm.Rand = (*RecordingRand)(nil)
|
||||
// NewRecordingRand returns a vm.Rand implementation that proxies calls to a
|
||||
// full Lotus node via JSON-RPC, and records matching rules and responses so
|
||||
// they can later be embedded in test vectors.
|
||||
func NewRecordingRand(reporter Reporter, api v0api.FullNode) *RecordingRand {
|
||||
func NewRecordingRand(reporter Reporter, api v1api.FullNode) *RecordingRand {
|
||||
return &RecordingRand{reporter: reporter, api: api}
|
||||
}
|
||||
|
||||
@ -45,10 +45,10 @@ func (r *RecordingRand) loadHead() {
|
||||
|
||||
func (r *RecordingRand) GetChainRandomness(ctx context.Context, round abi.ChainEpoch) ([32]byte, error) {
|
||||
r.once.Do(r.loadHead)
|
||||
// FullNode's v0 ChainGetRandomnessFromTickets handles whether we should be looking forward or back
|
||||
ret, err := r.api.ChainGetRandomnessFromTickets(ctx, r.head, round)
|
||||
// FullNode's v1 ChainGetRandomnessFromTickets handles whether we should be looking forward or back
|
||||
ret, err := r.api.StateGetRandomnessDigestFromTickets(ctx, round, r.head)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
return [32]byte{}, err
|
||||
}
|
||||
|
||||
r.reporter.Logf("fetched and recorded chain randomness for: epoch=%d, result=%x", round, ret)
|
||||
@ -64,14 +64,14 @@ func (r *RecordingRand) GetChainRandomness(ctx context.Context, round abi.ChainE
|
||||
r.recorded = append(r.recorded, match)
|
||||
r.lk.Unlock()
|
||||
|
||||
return ret, err
|
||||
return *(*[32]byte)(ret), err
|
||||
}
|
||||
|
||||
func (r *RecordingRand) GetBeaconRandomness(ctx context.Context, round abi.ChainEpoch) ([32]byte, error) {
|
||||
r.once.Do(r.loadHead)
|
||||
ret, err := r.api.StateGetRandomnessFromBeacon(ctx, round, r.head)
|
||||
ret, err := r.api.StateGetRandomnessDigestFromBeacon(ctx, round, r.head)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
return [32]byte{}, err
|
||||
}
|
||||
|
||||
r.reporter.Logf("fetched and recorded beacon randomness for: epoch=%d, result=%x", round, ret)
|
||||
@ -87,7 +87,7 @@ func (r *RecordingRand) GetBeaconRandomness(ctx context.Context, round abi.Chain
|
||||
r.recorded = append(r.recorded, match)
|
||||
r.lk.Unlock()
|
||||
|
||||
return ret, err
|
||||
return *(*[32]byte)(ret), err
|
||||
}
|
||||
|
||||
func (r *RecordingRand) Recorded() schema.Randomness {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package conformance
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
@ -29,16 +28,14 @@ func NewReplayingRand(reporter Reporter, recorded schema.Randomness) *ReplayingR
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ReplayingRand) match(requested schema.RandomnessRule) ([]byte, bool) {
|
||||
func (r *ReplayingRand) match(requested schema.RandomnessRule) ([32]byte, bool) {
|
||||
for _, other := range r.recorded {
|
||||
if other.On.Kind == requested.Kind &&
|
||||
other.On.Epoch == requested.Epoch &&
|
||||
other.On.DomainSeparationTag == requested.DomainSeparationTag &&
|
||||
bytes.Equal(other.On.Entropy, requested.Entropy) {
|
||||
return other.Return, true
|
||||
other.On.Epoch == requested.Epoch {
|
||||
return *(*[32]byte)(other.Return), true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
return [32]byte{}, false
|
||||
}
|
||||
|
||||
func (r *ReplayingRand) GetChainRandomness(ctx context.Context, round abi.ChainEpoch) ([32]byte, error) {
|
||||
|
@ -6966,7 +6966,7 @@ Response:
|
||||
```
|
||||
|
||||
### StateGetRandomnessDigestFromBeacon
|
||||
StateGetRandomnessFromBeacon is used to sample the beacon for randomness.
|
||||
StateGetRandomnessDigestFromBeacon is used to sample the beacon for randomness.
|
||||
|
||||
|
||||
Perms: read
|
||||
@ -6989,7 +6989,7 @@ Inputs:
|
||||
Response: `"Bw=="`
|
||||
|
||||
### StateGetRandomnessDigestFromTickets
|
||||
StateGetRandomnessFromTickets is used to sample the chain for randomness.
|
||||
StateGetRandomnessDigestFromTickets. is used to sample the chain for randomness.
|
||||
|
||||
|
||||
Perms: read
|
||||
|
2
go.mod
2
go.mod
@ -59,7 +59,7 @@ require (
|
||||
github.com/filecoin-project/specs-actors/v6 v6.0.2
|
||||
github.com/filecoin-project/specs-actors/v7 v7.0.1
|
||||
github.com/filecoin-project/specs-actors/v8 v8.0.1
|
||||
github.com/filecoin-project/test-vectors/schema v0.0.5
|
||||
github.com/filecoin-project/test-vectors/schema v0.0.6-0.20230822140104-bed37e1ca04f
|
||||
github.com/gbrlsnchs/jwt/v3 v3.0.1
|
||||
github.com/gdamore/tcell/v2 v2.2.0
|
||||
github.com/go-openapi/spec v0.19.11
|
||||
|
4
go.sum
4
go.sum
@ -369,8 +369,8 @@ github.com/filecoin-project/specs-actors/v7 v7.0.1 h1:w72xCxijK7xs1qzmJiw+WYJaVt
|
||||
github.com/filecoin-project/specs-actors/v7 v7.0.1/go.mod h1:tPLEYXoXhcpyLh69Ccq91SOuLXsPWjHiY27CzawjUEk=
|
||||
github.com/filecoin-project/specs-actors/v8 v8.0.1 h1:4u0tIRJeT5G7F05lwLRIsDnsrN+bJ5Ixj6h49Q7uE2Y=
|
||||
github.com/filecoin-project/specs-actors/v8 v8.0.1/go.mod h1:UYIPg65iPWoFw5NEftREdJwv9b/5yaLKdCgTvNI/2FA=
|
||||
github.com/filecoin-project/test-vectors/schema v0.0.5 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg=
|
||||
github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
|
||||
github.com/filecoin-project/test-vectors/schema v0.0.6-0.20230822140104-bed37e1ca04f h1:Ho3kK/WetJ7wco2VhR/pOZ9HD/WWL1BDEzYRTFQK8dw=
|
||||
github.com/filecoin-project/test-vectors/schema v0.0.6-0.20230822140104-bed37e1ca04f/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ=
|
||||
github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
|
||||
|
Loading…
Reference in New Issue
Block a user