2019-11-15 16:38:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-11-16 12:34:52 +00:00
|
|
|
"bytes"
|
2019-11-15 16:38:56 +00:00
|
|
|
"container/list"
|
|
|
|
"context"
|
2020-01-19 16:18:47 +00:00
|
|
|
"encoding/json"
|
2020-01-08 16:29:46 +00:00
|
|
|
"math"
|
2019-11-22 16:20:56 +00:00
|
|
|
"sync"
|
|
|
|
|
2020-02-26 22:54:34 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-02-10 19:16:36 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
2020-02-26 22:54:34 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
2020-02-10 19:16:36 +00:00
|
|
|
|
2019-11-15 16:38:56 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
"github.com/filecoin-project/lotus/chain/store"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-05-28 00:06:29 +00:00
|
|
|
parmap "github.com/filecoin-project/lotus/lib/parmap"
|
2019-11-15 16:38:56 +00:00
|
|
|
)
|
|
|
|
|
2020-02-21 18:49:49 +00:00
|
|
|
func runSyncer(ctx context.Context, api api.FullNode, st *storage, maxBatch int) {
|
2019-11-15 16:38:56 +00:00
|
|
|
notifs, err := api.ChainNotify(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
for notif := range notifs {
|
|
|
|
for _, change := range notif {
|
|
|
|
switch change.Type {
|
|
|
|
case store.HCCurrent:
|
|
|
|
fallthrough
|
|
|
|
case store.HCApply:
|
2020-02-21 18:49:49 +00:00
|
|
|
syncHead(ctx, api, st, change.Val, maxBatch)
|
2019-11-15 16:38:56 +00:00
|
|
|
case store.HCRevert:
|
|
|
|
log.Warnf("revert todo")
|
|
|
|
}
|
2019-12-13 14:47:51 +00:00
|
|
|
|
|
|
|
if change.Type == store.HCCurrent {
|
|
|
|
go subMpool(ctx, api, st)
|
|
|
|
go subBlocks(ctx, api, st)
|
|
|
|
}
|
2019-11-15 16:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2019-11-16 12:34:52 +00:00
|
|
|
type minerKey struct {
|
|
|
|
addr address.Address
|
|
|
|
act types.Actor
|
|
|
|
stateroot cid.Cid
|
2020-06-24 17:39:45 +00:00
|
|
|
tsKey types.TipSetKey
|
2019-11-16 12:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type minerInfo struct {
|
2020-02-25 21:09:22 +00:00
|
|
|
state miner.State
|
|
|
|
info miner.MinerInfo
|
2019-12-11 23:31:59 +00:00
|
|
|
|
2020-02-26 22:54:34 +00:00
|
|
|
power big.Int
|
2019-12-11 23:31:59 +00:00
|
|
|
ssize uint64
|
|
|
|
psize uint64
|
2019-11-16 12:34:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-19 16:18:47 +00:00
|
|
|
type actorInfo struct {
|
|
|
|
stateroot cid.Cid
|
2020-06-24 17:39:45 +00:00
|
|
|
tsKey types.TipSetKey
|
2020-01-19 16:18:47 +00:00
|
|
|
state string
|
|
|
|
}
|
|
|
|
|
2020-06-24 17:39:45 +00:00
|
|
|
func syncHead(ctx context.Context, api api.FullNode, st *storage, headTs *types.TipSet, maxBatch int) {
|
2019-11-15 18:37:57 +00:00
|
|
|
var alk sync.Mutex
|
|
|
|
|
2019-12-11 22:17:44 +00:00
|
|
|
log.Infof("Getting synced block list")
|
|
|
|
|
|
|
|
hazlist := st.hasList()
|
|
|
|
|
2019-11-15 18:37:57 +00:00
|
|
|
log.Infof("Getting headers / actors")
|
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
allToSync := map[cid.Cid]*types.BlockHeader{}
|
2019-11-15 16:38:56 +00:00
|
|
|
toVisit := list.New()
|
|
|
|
|
2020-06-24 17:39:45 +00:00
|
|
|
for _, header := range headTs.Blocks() {
|
2019-11-15 16:38:56 +00:00
|
|
|
toVisit.PushBack(header)
|
|
|
|
}
|
|
|
|
|
|
|
|
for toVisit.Len() > 0 {
|
|
|
|
bh := toVisit.Remove(toVisit.Back()).(*types.BlockHeader)
|
|
|
|
|
2019-12-11 22:17:44 +00:00
|
|
|
_, has := hazlist[bh.Cid()]
|
2020-01-08 16:29:46 +00:00
|
|
|
if _, seen := allToSync[bh.Cid()]; seen || has {
|
2019-11-15 18:37:57 +00:00
|
|
|
continue
|
2019-11-15 16:38:56 +00:00
|
|
|
}
|
2019-11-15 18:37:57 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
allToSync[bh.Cid()] = bh
|
2019-11-15 18:37:57 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
if len(allToSync)%500 == 10 {
|
|
|
|
log.Infof("todo: (%d) %s @%d", len(allToSync), bh.Cid(), bh.Height)
|
2019-11-15 16:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(bh.Parents) == 0 {
|
2019-11-15 18:37:57 +00:00
|
|
|
continue
|
2019-11-15 16:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pts, err := api.ChainGetTipSet(ctx, types.NewTipSetKey(bh.Parents...))
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, header := range pts.Blocks() {
|
|
|
|
toVisit.PushBack(header)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
for len(allToSync) > 0 {
|
2020-02-20 03:06:41 +00:00
|
|
|
actors := map[address.Address]map[types.Actor]actorInfo{}
|
2020-06-24 17:39:45 +00:00
|
|
|
addressToID := map[address.Address]address.Address{}
|
2020-02-26 09:05:22 +00:00
|
|
|
minH := abi.ChainEpoch(math.MaxInt64)
|
2019-11-15 16:38:56 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
for _, header := range allToSync {
|
|
|
|
if header.Height < minH {
|
|
|
|
minH = header.Height
|
|
|
|
}
|
2019-11-15 18:37:57 +00:00
|
|
|
}
|
2019-11-16 12:34:52 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
toSync := map[cid.Cid]*types.BlockHeader{}
|
|
|
|
for c, header := range allToSync {
|
2020-02-26 09:05:22 +00:00
|
|
|
if header.Height < minH+abi.ChainEpoch(maxBatch) {
|
2020-01-08 16:29:46 +00:00
|
|
|
toSync[c] = header
|
2020-06-24 17:39:45 +00:00
|
|
|
addressToID[header.Miner] = address.Undef
|
2020-01-08 16:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for c := range toSync {
|
|
|
|
delete(allToSync, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infof("Syncing %d blocks", len(toSync))
|
|
|
|
|
|
|
|
paDone := 0
|
2020-05-28 00:06:29 +00:00
|
|
|
parmap.Par(50, parmap.MapArr(toSync), func(bh *types.BlockHeader) {
|
2020-01-08 16:29:46 +00:00
|
|
|
paDone++
|
|
|
|
if paDone%100 == 0 {
|
|
|
|
log.Infof("pa: %d %d%%", paDone, (paDone*100)/len(toSync))
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(bh.Parents) == 0 { // genesis case
|
2020-06-24 17:39:45 +00:00
|
|
|
genesisTs, _ := types.NewTipSet([]*types.BlockHeader{bh})
|
|
|
|
aadrs, err := api.StateListActors(ctx, genesisTs.Key())
|
2020-01-08 16:29:46 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:06:29 +00:00
|
|
|
parmap.Par(50, aadrs, func(addr address.Address) {
|
2020-06-24 17:39:45 +00:00
|
|
|
act, err := api.StateGetActor(ctx, addr, genesisTs.Key())
|
2020-01-08 16:29:46 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2020-06-17 05:10:29 +00:00
|
|
|
|
|
|
|
ast, err := api.StateReadState(ctx, addr, genesisTs.Key())
|
2020-01-19 16:18:47 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
state, err := json.Marshal(ast.State)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
alk.Lock()
|
|
|
|
_, ok := actors[addr]
|
|
|
|
if !ok {
|
2020-01-19 16:18:47 +00:00
|
|
|
actors[addr] = map[types.Actor]actorInfo{}
|
|
|
|
}
|
|
|
|
actors[addr][*act] = actorInfo{
|
|
|
|
stateroot: bh.ParentStateRoot,
|
2020-06-24 17:39:45 +00:00
|
|
|
tsKey: genesisTs.Key(),
|
2020-01-19 16:18:47 +00:00
|
|
|
state: string(state),
|
2020-01-08 16:29:46 +00:00
|
|
|
}
|
2020-06-24 17:39:45 +00:00
|
|
|
addressToID[addr] = address.Undef
|
2020-01-08 16:29:46 +00:00
|
|
|
alk.Unlock()
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pts, err := api.ChainGetTipSet(ctx, types.NewTipSetKey(bh.Parents...))
|
2019-11-16 12:34:52 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
changes, err := api.StateChangedActors(ctx, pts.ParentState(), bh.ParentStateRoot)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for a, act := range changes {
|
2020-05-27 20:53:20 +00:00
|
|
|
act := act
|
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
addr, err := address.NewFromString(a)
|
2019-11-16 12:34:52 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2020-06-24 17:39:45 +00:00
|
|
|
|
2020-06-17 05:10:29 +00:00
|
|
|
ast, err := api.StateReadState(ctx, addr, pts.Key())
|
|
|
|
|
2020-01-19 16:18:47 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2020-06-24 17:39:45 +00:00
|
|
|
|
2020-01-19 16:18:47 +00:00
|
|
|
state, err := json.Marshal(ast.State)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2020-01-08 16:29:46 +00:00
|
|
|
|
2019-11-16 12:34:52 +00:00
|
|
|
alk.Lock()
|
|
|
|
_, ok := actors[addr]
|
|
|
|
if !ok {
|
2020-01-19 16:18:47 +00:00
|
|
|
actors[addr] = map[types.Actor]actorInfo{}
|
|
|
|
}
|
|
|
|
actors[addr][act] = actorInfo{
|
|
|
|
stateroot: bh.ParentStateRoot,
|
|
|
|
state: string(state),
|
2020-06-24 17:39:45 +00:00
|
|
|
tsKey: pts.Key(),
|
2019-11-16 12:34:52 +00:00
|
|
|
}
|
2020-06-24 17:39:45 +00:00
|
|
|
addressToID[addr] = address.Undef
|
2019-11-16 12:34:52 +00:00
|
|
|
alk.Unlock()
|
2020-01-08 16:29:46 +00:00
|
|
|
}
|
|
|
|
})
|
2019-11-16 12:34:52 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
log.Infof("Getting messages")
|
2019-11-16 12:34:52 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
msgs, incls := fetchMessages(ctx, api, toSync)
|
2019-11-16 12:34:52 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
log.Infof("Resolving addresses")
|
|
|
|
|
|
|
|
for _, message := range msgs {
|
2020-06-24 17:39:45 +00:00
|
|
|
addressToID[message.To] = address.Undef
|
|
|
|
addressToID[message.From] = address.Undef
|
2019-11-15 18:37:57 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 17:39:45 +00:00
|
|
|
parmap.Par(50, parmap.KMapArr(addressToID), func(addr address.Address) {
|
|
|
|
// FIXME: cannot use EmptyTSK here since actorID's can change during reorgs, need to use the corresponding tipset.
|
|
|
|
// TODO: figure out a way to get the corresponding tipset...
|
2020-02-11 23:29:45 +00:00
|
|
|
raddr, err := api.StateLookupID(ctx, addr, types.EmptyTSK)
|
2019-11-15 18:37:57 +00:00
|
|
|
if err != nil {
|
2020-01-08 16:29:46 +00:00
|
|
|
log.Warn(err)
|
2019-11-15 18:37:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
alk.Lock()
|
2020-06-24 17:39:45 +00:00
|
|
|
addressToID[addr] = raddr
|
2019-11-15 18:37:57 +00:00
|
|
|
alk.Unlock()
|
2020-01-08 16:29:46 +00:00
|
|
|
})
|
2019-12-12 18:34:28 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
log.Infof("Getting miner info")
|
2019-12-12 18:34:28 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
miners := map[minerKey]*minerInfo{}
|
2019-12-12 18:34:28 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
for addr, m := range actors {
|
|
|
|
for actor, c := range m {
|
2020-02-25 21:09:22 +00:00
|
|
|
if actor.Code != builtin.StorageMinerActorCodeID {
|
2020-01-08 16:29:46 +00:00
|
|
|
continue
|
|
|
|
}
|
2019-11-15 18:37:57 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
miners[minerKey{
|
|
|
|
addr: addr,
|
|
|
|
act: actor,
|
2020-01-19 16:18:47 +00:00
|
|
|
stateroot: c.stateroot,
|
2020-06-24 17:39:45 +00:00
|
|
|
tsKey: c.tsKey,
|
2020-01-08 16:29:46 +00:00
|
|
|
}] = &minerInfo{}
|
|
|
|
}
|
2019-12-12 18:34:28 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 00:06:29 +00:00
|
|
|
parmap.Par(50, parmap.KVMapArr(miners), func(it func() (minerKey, *minerInfo)) {
|
2020-01-08 16:29:46 +00:00
|
|
|
k, info := it()
|
2019-11-16 12:34:52 +00:00
|
|
|
|
2020-06-24 17:39:45 +00:00
|
|
|
// TODO: get the storage power actors state and and pull the miner power from there, currently this hits the
|
|
|
|
// storage power actor once for each miner for each tipset, we can do better by just getting it for each tipset
|
|
|
|
// and reading each miner power from the result.
|
|
|
|
pow, err := api.StateMinerPower(ctx, k.addr, k.tsKey)
|
2020-02-26 22:54:34 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
// Not sure why this would fail, but its probably worth continuing
|
|
|
|
}
|
2020-04-17 23:14:39 +00:00
|
|
|
info.power = pow.MinerPower.QualityAdjPower
|
2020-02-26 22:54:34 +00:00
|
|
|
|
2020-06-24 17:39:45 +00:00
|
|
|
sszs, err := api.StateMinerSectorCount(ctx, k.addr, k.tsKey)
|
2020-01-08 16:29:46 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
info.psize = sszs.Pset
|
|
|
|
info.ssize = sszs.Sset
|
2019-11-16 12:34:52 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
astb, err := api.ChainReadObj(ctx, k.act.Head)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
2019-11-16 12:34:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
if err := info.state.UnmarshalCBOR(bytes.NewReader(astb)); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2019-11-16 12:34:52 +00:00
|
|
|
|
2020-02-25 21:09:22 +00:00
|
|
|
info.info = info.state.Info
|
2020-01-08 16:29:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
log.Info("Getting receipts")
|
|
|
|
|
|
|
|
receipts := fetchParentReceipts(ctx, api, toSync)
|
|
|
|
|
|
|
|
log.Info("Storing headers")
|
|
|
|
|
|
|
|
if err := st.storeHeaders(toSync, true); err != nil {
|
|
|
|
log.Errorf("%+v", err)
|
2019-12-11 23:31:59 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
log.Info("Storing address mapping")
|
|
|
|
|
2020-06-24 17:39:45 +00:00
|
|
|
if err := st.storeAddressMap(addressToID); err != nil {
|
2019-11-16 12:34:52 +00:00
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
log.Info("Storing actors")
|
|
|
|
|
|
|
|
if err := st.storeActors(actors); err != nil {
|
2019-11-16 12:34:52 +00:00
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
log.Info("Storing miners")
|
|
|
|
|
|
|
|
if err := st.storeMiners(miners); err != nil {
|
2019-11-16 12:34:52 +00:00
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
log.Infof("Storing messages")
|
|
|
|
|
|
|
|
if err := st.storeMessages(msgs); err != nil {
|
2019-11-16 12:34:52 +00:00
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2019-12-12 18:34:28 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
log.Info("Storing message inclusions")
|
2019-12-12 18:34:28 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
if err := st.storeMsgInclusions(incls); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2019-12-10 23:42:36 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
log.Infof("Storing parent receipts")
|
2019-12-10 23:42:36 +00:00
|
|
|
|
2020-01-08 16:29:46 +00:00
|
|
|
if err := st.storeReceipts(receipts); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Infof("Sync stage done")
|
2019-12-10 23:42:36 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 00:49:52 +00:00
|
|
|
log.Infof("Get deals")
|
|
|
|
|
|
|
|
// TODO: incremental, gather expired
|
2020-06-24 17:39:45 +00:00
|
|
|
deals, err := api.StateMarketDeals(ctx, headTs.Key())
|
2020-01-20 00:49:52 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infof("Store deals")
|
|
|
|
|
|
|
|
if err := st.storeDeals(deals); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-22 15:10:22 +00:00
|
|
|
log.Infof("Refresh views")
|
|
|
|
|
|
|
|
if err := st.refreshViews(); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-15 16:38:56 +00:00
|
|
|
log.Infof("Sync done")
|
|
|
|
}
|
|
|
|
|
2019-11-15 18:37:57 +00:00
|
|
|
func fetchMessages(ctx context.Context, api api.FullNode, toSync map[cid.Cid]*types.BlockHeader) (map[cid.Cid]*types.Message, map[cid.Cid][]cid.Cid) {
|
2019-11-15 16:38:56 +00:00
|
|
|
var lk sync.Mutex
|
|
|
|
messages := map[cid.Cid]*types.Message{}
|
|
|
|
inclusions := map[cid.Cid][]cid.Cid{} // block -> msgs
|
|
|
|
|
2020-05-28 00:06:29 +00:00
|
|
|
parmap.Par(50, parmap.MapArr(toSync), func(header *types.BlockHeader) {
|
2019-11-15 18:37:57 +00:00
|
|
|
msgs, err := api.ChainGetBlockMessages(ctx, header.Cid())
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
2019-11-15 16:38:56 +00:00
|
|
|
}
|
|
|
|
|
2019-11-15 18:37:57 +00:00
|
|
|
vmm := make([]*types.Message, 0, len(msgs.Cids))
|
|
|
|
for _, m := range msgs.BlsMessages {
|
|
|
|
vmm = append(vmm, m)
|
|
|
|
}
|
2019-11-15 16:38:56 +00:00
|
|
|
|
2019-11-15 18:37:57 +00:00
|
|
|
for _, m := range msgs.SecpkMessages {
|
|
|
|
vmm = append(vmm, &m.Message)
|
|
|
|
}
|
2019-11-15 16:38:56 +00:00
|
|
|
|
2019-11-15 18:37:57 +00:00
|
|
|
lk.Lock()
|
|
|
|
for _, message := range vmm {
|
|
|
|
messages[message.Cid()] = message
|
|
|
|
inclusions[header.Cid()] = append(inclusions[header.Cid()], message.Cid())
|
|
|
|
}
|
|
|
|
lk.Unlock()
|
|
|
|
})
|
2019-11-15 16:38:56 +00:00
|
|
|
|
|
|
|
return messages, inclusions
|
|
|
|
}
|
2019-12-03 11:05:12 +00:00
|
|
|
|
|
|
|
type mrec struct {
|
|
|
|
msg cid.Cid
|
|
|
|
state cid.Cid
|
|
|
|
idx int
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchParentReceipts(ctx context.Context, api api.FullNode, toSync map[cid.Cid]*types.BlockHeader) map[mrec]*types.MessageReceipt {
|
|
|
|
var lk sync.Mutex
|
|
|
|
out := map[mrec]*types.MessageReceipt{}
|
|
|
|
|
2020-05-28 00:06:29 +00:00
|
|
|
parmap.Par(50, parmap.MapArr(toSync), func(header *types.BlockHeader) {
|
2019-12-03 11:05:12 +00:00
|
|
|
recs, err := api.ChainGetParentReceipts(ctx, header.Cid())
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
msgs, err := api.ChainGetParentMessages(ctx, header.Cid())
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
lk.Lock()
|
|
|
|
for i, r := range recs {
|
|
|
|
out[mrec{
|
|
|
|
msg: msgs[i].Cid,
|
|
|
|
state: header.ParentStateRoot,
|
|
|
|
idx: i,
|
|
|
|
}] = r
|
|
|
|
}
|
|
|
|
lk.Unlock()
|
|
|
|
})
|
|
|
|
|
|
|
|
return out
|
|
|
|
}
|