diff --git a/api/struct.go b/api/struct.go index 84163742d..e6db41d14 100644 --- a/api/struct.go +++ b/api/struct.go @@ -82,7 +82,7 @@ type FullNodeStruct struct { StateMinerPeerID func(ctx context.Context, m address.Address, ts *types.TipSet) (peer.ID, error) `perm:"read"` StateMinerProvingPeriodEnd func(ctx context.Context, actor address.Address, ts *types.TipSet) (uint64, error) `perm:"read"` StateCall func(context.Context, *types.Message, *types.TipSet) (*types.MessageReceipt, error) `perm:"read"` - StateReplay func(context.Context, *types.TipSet, cid.Cid) (*ReplayResults, error) `perm:"read"` + StateReplay func(context.Context, *types.TipSet, cid.Cid) (*ReplayResults, error) `perm:"read"` StateGetActor func(context.Context, address.Address, *types.TipSet) (*types.Actor, error) `perm:"read"` StateReadState func(context.Context, *types.Actor, *types.TipSet) (*ActorState, error) `perm:"read"` diff --git a/chain/gen/gen.go b/chain/gen/gen.go index e4b700196..d7d1bef86 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -360,7 +360,7 @@ type mca struct { } func (mca mca) ChainGetRandomness(ctx context.Context, pts *types.TipSet, ticks []*types.Ticket, lb int) ([]byte, error) { - return mca.sm.ChainStore().GetRandomness(ctx, pts, ticks, int64(lb)) + return mca.sm.ChainStore().GetRandomness(ctx, pts.Cids(), ticks, int64(lb)) } func (mca mca) StateMinerPower(ctx context.Context, maddr address.Address, ts *types.TipSet) (api.MinerPower, error) { diff --git a/chain/gen/mining.go b/chain/gen/mining.go index 3b34e5d56..af0adccb9 100644 --- a/chain/gen/mining.go +++ b/chain/gen/mining.go @@ -27,7 +27,7 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal height := parents.Height() + uint64(len(tickets)) - r := vm.NewChainRand(sm.ChainStore(), parents, tickets) + r := vm.NewChainRand(sm.ChainStore(), parents.Cids(), parents.Height(), tickets) vmi, err := vm.NewVM(st, height, r, miner, sm.ChainStore()) if err != nil { return nil, err diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index ba375a2d6..a2fae8c63 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -58,7 +58,7 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. return nil, err } - r := vm.NewChainRand(sm.cs, ts, nil) + r := vm.NewChainRand(sm.cs, ts.Cids(), ts.Height(), nil) return sm.CallRaw(ctx, msg, state, r, ts.Height()) } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 7fc0d8205..1d1afd846 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -77,7 +77,12 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl return cid.Undef, xerrors.Errorf("recursive TipSetState failed: %w", err) } - r := vm.NewChainRand(sm.cs, blks[0], nil) + cids := make([]cid.Cid, len(blks)) + for i, v := range blks { + cids[i] = v.Cid() + } + + r := vm.NewChainRand(sm.cs, cids, blks[0].Height, nil) vmi, err := vm.NewVM(pstate, blks[0].Height, r, address.Undef, sm.cs) if err != nil { diff --git a/chain/store/store.go b/chain/store/store.go index a797524d4..e95ccb2a7 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -702,7 +702,7 @@ func (cs *ChainStore) TryFillTipSet(ts *types.TipSet) (*FullTipSet, error) { return NewFullTipSet(out), nil } -func (cs *ChainStore) GetRandomness(ctx context.Context, pts *types.TipSet, tickets []*types.Ticket, lb int64) ([]byte, error) { +func (cs *ChainStore) GetRandomness(ctx context.Context, blks []cid.Cid, tickets []*types.Ticket, lb int64) ([]byte, error) { if lb < 0 { return nil, fmt.Errorf("negative lookback parameters are not valid (got %d)", lb) } @@ -717,9 +717,8 @@ func (cs *ChainStore) GetRandomness(ctx context.Context, pts *types.TipSet, tick nv := lb - lt - nextCids := pts.Cids() for { - nts, err := cs.LoadTipSet(nextCids) + nts, err := cs.LoadTipSet(blks) if err != nil { return nil, err } @@ -748,7 +747,7 @@ func (cs *ChainStore) GetRandomness(ctx context.Context, pts *types.TipSet, tick return rval, nil } - nextCids = mtb.Parents + blks = mtb.Parents } } diff --git a/chain/sync.go b/chain/sync.go index b9de70f4e..1ebb2b9e9 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -422,7 +422,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err return xerrors.Errorf("validating block tickets failed: %w", err) } - rand, err := syncer.sm.ChainStore().GetRandomness(ctx, baseTs, h.Tickets, build.RandomnessLookback) + rand, err := syncer.sm.ChainStore().GetRandomness(ctx, baseTs.Cids(), h.Tickets, build.RandomnessLookback) if err != nil { return xerrors.Errorf("failed to get randomness for verifying election proof: %w", err) } @@ -440,7 +440,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err return xerrors.Errorf("miner created a block but was not a winner") } - r := vm.NewChainRand(syncer.store, baseTs, h.Tickets) + r := vm.NewChainRand(syncer.store, baseTs.Cids(), baseTs.Height(), h.Tickets) vmi, err := vm.NewVM(stateroot, h.Height, r, h.Miner, syncer.store) if err != nil { return xerrors.Errorf("failed to instantiate VM: %w", err) diff --git a/chain/vm/vm.go b/chain/vm/vm.go index f5c8a21b1..c83187503 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -318,21 +318,23 @@ type Rand interface { type chainRand struct { cs *store.ChainStore - pts *types.TipSet + blks []cid.Cid + bh uint64 tickets []*types.Ticket } -func NewChainRand(cs *store.ChainStore, pts *types.TipSet, tickets []*types.Ticket) Rand { +func NewChainRand(cs *store.ChainStore, blks []cid.Cid, bheight uint64, tickets []*types.Ticket) Rand { return &chainRand{ cs: cs, - pts: pts, + blks: blks, + bh: bheight, tickets: tickets, } } func (cr *chainRand) GetRandomness(ctx context.Context, h int64) ([]byte, error) { - lb := (int64(cr.pts.Height()) + int64(len(cr.tickets))) - h - return cr.cs.GetRandomness(ctx, cr.pts, cr.tickets, lb) + lb := (int64(cr.bh) + int64(len(cr.tickets))) - h + return cr.cs.GetRandomness(ctx, cr.blks, cr.tickets, lb) } type ApplyRet struct { diff --git a/node/impl/full/chain.go b/node/impl/full/chain.go index a9e0482c5..51de87165 100644 --- a/node/impl/full/chain.go +++ b/node/impl/full/chain.go @@ -45,7 +45,7 @@ func (a *ChainAPI) ChainHead(context.Context) (*types.TipSet, error) { } func (a *ChainAPI) ChainGetRandomness(ctx context.Context, pts *types.TipSet, tickets []*types.Ticket, lb int) ([]byte, error) { - return a.Chain.GetRandomness(ctx, pts, tickets, int64(lb)) + return a.Chain.GetRandomness(ctx, pts.Cids(), tickets, int64(lb)) } func (a *ChainAPI) ChainWaitMsg(ctx context.Context, msg cid.Cid) (*api.MsgWait, error) {