lotus/cmd/lotus-chainwatch/mpool.go

61 lines
1004 B
Go
Raw Normal View History

package main
import (
"context"
2019-12-13 11:04:24 +00:00
"time"
"github.com/ipfs/go-cid"
aapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types"
)
func subMpool(ctx context.Context, api aapi.FullNode, st *storage) {
sub, err := api.MpoolSub(ctx)
if err != nil {
return
}
2019-12-13 11:04:24 +00:00
for {
var updates []aapi.MpoolUpdate
2019-12-13 11:04:24 +00:00
select {
case update := <-sub:
updates = append(updates, update)
case <-ctx.Done():
return
}
2019-11-19 19:53:24 +00:00
2019-12-13 11:04:24 +00:00
loop:
for {
time.Sleep(10 * time.Millisecond)
select {
case update := <-sub:
updates = append(updates, update)
default:
break loop
2019-12-13 09:30:51 +00:00
}
2019-12-13 11:04:24 +00:00
}
2019-12-13 09:30:51 +00:00
2019-12-13 11:04:24 +00:00
msgs := map[cid.Cid]*types.Message{}
for _, v := range updates {
if v.Type != aapi.MpoolAdd {
continue
2019-12-13 09:30:51 +00:00
}
2019-12-13 11:04:24 +00:00
msgs[v.Message.Message.Cid()] = &v.Message.Message
}
log.Infof("Processing %d mpool updates", len(msgs))
err := st.storeMessages(msgs)
if err != nil {
log.Error(err)
}
if err := st.storeMpoolInclusions(updates); err != nil {
log.Error(err)
}
}
}