2019-11-17 12:01:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-12-13 11:04:24 +00:00
|
|
|
"time"
|
2019-11-17 12:01:10 +00:00
|
|
|
|
|
|
|
"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-11-17 12:01:10 +00:00
|
|
|
|
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-11-17 12:01:10 +00:00
|
|
|
|
2019-12-13 11:04:24 +00:00
|
|
|
msgs[v.Message.Message.Cid()] = &v.Message.Message
|
|
|
|
}
|
|
|
|
|
2020-06-25 00:57:51 +00:00
|
|
|
log.Debugf("Processing %d mpool updates", len(msgs))
|
2019-12-13 11:04:24 +00:00
|
|
|
|
|
|
|
err := st.storeMessages(msgs)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := st.storeMpoolInclusions(updates); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
2019-11-17 12:01:10 +00:00
|
|
|
}
|
|
|
|
}
|