mirror of
https://github.com/filecoin-project/lotus.git
synced 2025-08-24 01:08:42 +08:00

* fix(drand): `StateGetBeaconEntry` uses chain beacons for historical epochs Fixes: https://github.com/filecoin-project/lotus/issues/12414 Previously StateGetBeaconEntry would always try and use a drand beacon to get the appropriate round. But as drand has shut down old beacons and we've removed client details from Lotus, it has stopped working for historical beacons. This fix restores historical beacon entries by using the on-chain lookup, however it now follows the rules used by StateGetRandomnessFromBeacon and the get_beacon_randomness syscall which has some quirks with null rounds prior to nv14. See https://github.com/filecoin-project/lotus/issues/12414#issuecomment-2320034935 for specifics. StateGetBeaconEntry still blocks for future epochs and uses live drand beacon clients to wait for and fetch rounds as they are available. * fixup! fix(drand): `StateGetBeaconEntry` uses chain beacons for historical epochs * fixup! fix(drand): `StateGetBeaconEntry` uses chain beacons for historical epochs
33 lines
992 B
Go
33 lines
992 B
Go
package conformance
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/lotus/chain/rand"
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
)
|
|
|
|
type fixedRand struct{}
|
|
|
|
var _ rand.Rand = (*fixedRand)(nil)
|
|
|
|
// NewFixedRand creates a test vm.Rand that always returns fixed bytes value
|
|
// of utf-8 string 'i_am_random_____i_am_random_____'.
|
|
func NewFixedRand() rand.Rand {
|
|
return &fixedRand{}
|
|
}
|
|
|
|
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) GetBeaconEntry(_ context.Context, _ abi.ChainEpoch) (*types.BeaconEntry, error) {
|
|
return &types.BeaconEntry{Round: 10, Data: []byte("i_am_random_____i_am_random_____")}, nil
|
|
}
|
|
|
|
func (r *fixedRand) GetBeaconRandomness(_ context.Context, _ abi.ChainEpoch) ([32]byte, error) {
|
|
return *(*[32]byte)([]byte("i_am_random_____i_am_random_____")), nil // 32 bytes.
|
|
}
|