recover from errors in head change

This commit is contained in:
vyzo 2020-08-21 20:17:30 +03:00
parent d022dba14a
commit 161cb32078

View File

@ -12,6 +12,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/hashicorp/go-multierror"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
@ -744,30 +745,42 @@ func (mp *MessagePool) HeadChange(revert []*types.TipSet, apply []*types.TipSet)
} }
} }
var merr error
for _, ts := range revert { for _, ts := range revert {
pts, err := mp.api.LoadTipSet(ts.Parents()) pts, err := mp.api.LoadTipSet(ts.Parents())
if err != nil { if err != nil {
return err log.Errorf("error loading reverted tipset parent: %s", err)
} merr = multierror.Append(merr, err)
continue
msgs, err := mp.MessagesForBlocks(ts.Blocks())
if err != nil {
return err
} }
mp.curTs = pts mp.curTs = pts
msgs, err := mp.MessagesForBlocks(ts.Blocks())
if err != nil {
log.Errorf("error retrieving messages for reverted block: %s", err)
merr = multierror.Append(merr, err)
continue
}
for _, msg := range msgs { for _, msg := range msgs {
add(msg) add(msg)
} }
} }
for _, ts := range apply { for _, ts := range apply {
mp.curTs = ts
for _, b := range ts.Blocks() { for _, b := range ts.Blocks() {
bmsgs, smsgs, err := mp.api.MessagesForBlock(b) bmsgs, smsgs, err := mp.api.MessagesForBlock(b)
if err != nil { if err != nil {
return xerrors.Errorf("failed to get messages for apply block %s(height %d) (msgroot = %s): %w", b.Cid(), b.Height, b.Messages, err) xerr := xerrors.Errorf("failed to get messages for apply block %s(height %d) (msgroot = %s): %w", b.Cid(), b.Height, b.Messages, err)
log.Errorf("error retrieving messages for block: %s", xerr)
merr = multierror.Append(merr, xerr)
continue
} }
for _, msg := range smsgs { for _, msg := range smsgs {
rm(msg.Message.From, msg.Message.Nonce) rm(msg.Message.From, msg.Message.Nonce)
maybeRepub(msg.Cid()) maybeRepub(msg.Cid())
@ -778,8 +791,6 @@ func (mp *MessagePool) HeadChange(revert []*types.TipSet, apply []*types.TipSet)
maybeRepub(msg.Cid()) maybeRepub(msg.Cid())
} }
} }
mp.curTs = ts
} }
if repubTrigger { if repubTrigger {
@ -862,7 +873,7 @@ func (mp *MessagePool) HeadChange(revert []*types.TipSet, apply []*types.TipSet)
} }
} }
return nil return merr
} }
type statBucket struct { type statBucket struct {