From 91ee13b4611ad2570ed7856e801fc38f4934114a Mon Sep 17 00:00:00 2001 From: Aayush Date: Mon, 21 Aug 2023 16:26:51 -0400 Subject: [PATCH] fix: refactor rand_replay --- conformance/rand_record.go | 25 ++++++++++--------------- conformance/rand_replay.go | 29 ++++++++++++----------------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/conformance/rand_record.go b/conformance/rand_record.go index 277c984a7..e6df0c397 100644 --- a/conformance/rand_record.go +++ b/conformance/rand_record.go @@ -6,7 +6,6 @@ import ( "sync" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/test-vectors/schema" "github.com/filecoin-project/lotus/api/v0api" @@ -44,22 +43,20 @@ func (r *RecordingRand) loadHead() { r.head = head.Key() } -func (r *RecordingRand) GetChainRandomness(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) { +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, pers, round, entropy) + ret, err := r.api.ChainGetRandomnessFromTickets(ctx, r.head, round) if err != nil { return ret, err } - r.reporter.Logf("fetched and recorded chain randomness for: dst=%d, epoch=%d, entropy=%x, result=%x", pers, round, entropy, ret) + r.reporter.Logf("fetched and recorded chain randomness for: epoch=%d, result=%x", round, ret) match := schema.RandomnessMatch{ On: schema.RandomnessRule{ - Kind: schema.RandomnessChain, - DomainSeparationTag: int64(pers), - Epoch: int64(round), - Entropy: entropy, + Kind: schema.RandomnessChain, + Epoch: int64(round), }, Return: []byte(ret), } @@ -70,21 +67,19 @@ func (r *RecordingRand) GetChainRandomness(ctx context.Context, pers crypto.Doma return ret, err } -func (r *RecordingRand) GetBeaconRandomness(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) { +func (r *RecordingRand) GetBeaconRandomness(ctx context.Context, round abi.ChainEpoch) ([32]byte, error) { r.once.Do(r.loadHead) - ret, err := r.api.StateGetRandomnessFromBeacon(ctx, pers, round, entropy, r.head) + ret, err := r.api.StateGetRandomnessFromBeacon(ctx, round, r.head) if err != nil { return ret, err } - r.reporter.Logf("fetched and recorded beacon randomness for: dst=%d, epoch=%d, entropy=%x, result=%x", pers, round, entropy, ret) + r.reporter.Logf("fetched and recorded beacon randomness for: epoch=%d, result=%x", round, ret) match := schema.RandomnessMatch{ On: schema.RandomnessRule{ - Kind: schema.RandomnessBeacon, - DomainSeparationTag: int64(pers), - Epoch: int64(round), - Entropy: entropy, + Kind: schema.RandomnessBeacon, + Epoch: int64(round), }, Return: []byte(ret), } diff --git a/conformance/rand_replay.go b/conformance/rand_replay.go index ef19e41bb..74f1667f1 100644 --- a/conformance/rand_replay.go +++ b/conformance/rand_replay.go @@ -5,7 +5,6 @@ import ( "context" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/test-vectors/schema" "github.com/filecoin-project/lotus/chain/vm" @@ -42,38 +41,34 @@ func (r *ReplayingRand) match(requested schema.RandomnessRule) ([]byte, bool) { return nil, false } -func (r *ReplayingRand) GetChainRandomness(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) { +func (r *ReplayingRand) GetChainRandomness(ctx context.Context, round abi.ChainEpoch) ([32]byte, error) { rule := schema.RandomnessRule{ - Kind: schema.RandomnessChain, - DomainSeparationTag: int64(pers), - Epoch: int64(round), - Entropy: entropy, + Kind: schema.RandomnessChain, + Epoch: int64(round), } if ret, ok := r.match(rule); ok { - r.reporter.Logf("returning saved chain randomness: dst=%d, epoch=%d, entropy=%x, result=%x", pers, round, entropy, ret) + r.reporter.Logf("returning saved chain randomness: epoch=%d, result=%x", round, ret) return ret, nil } - r.reporter.Logf("returning fallback chain randomness: dst=%d, epoch=%d, entropy=%x", pers, round, entropy) + r.reporter.Logf("returning fallback chain randomness: epoch=%d", round) - return r.fallback.GetChainRandomness(ctx, pers, round, entropy) + return r.fallback.GetChainRandomness(ctx, round) } -func (r *ReplayingRand) GetBeaconRandomness(ctx context.Context, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) { +func (r *ReplayingRand) GetBeaconRandomness(ctx context.Context, round abi.ChainEpoch) ([32]byte, error) { rule := schema.RandomnessRule{ - Kind: schema.RandomnessBeacon, - DomainSeparationTag: int64(pers), - Epoch: int64(round), - Entropy: entropy, + Kind: schema.RandomnessBeacon, + Epoch: int64(round), } if ret, ok := r.match(rule); ok { - r.reporter.Logf("returning saved beacon randomness: dst=%d, epoch=%d, entropy=%x, result=%x", pers, round, entropy, ret) + r.reporter.Logf("returning saved beacon randomness: epoch=%d, result=%x", round, ret) return ret, nil } - r.reporter.Logf("returning fallback beacon randomness: dst=%d, epoch=%d, entropy=%x", pers, round, entropy) + r.reporter.Logf("returning fallback beacon randomness: epoch=%d, ", round) - return r.fallback.GetBeaconRandomness(ctx, pers, round, entropy) + return r.fallback.GetBeaconRandomness(ctx, round) }