@@ -12,6 +12,7 @@ import (
12
12
13
13
"github.com/filecoin-project/specs-actors/actors/abi"
14
14
"github.com/filecoin-project/specs-actors/actors/crypto"
15
+ "github.com/hashicorp/go-multierror"
15
16
lru "github.com/hashicorp/golang-lru"
16
17
"github.com/ipfs/go-cid"
17
18
"github.com/ipfs/go-datastore"
@@ -744,30 +745,42 @@ func (mp *MessagePool) HeadChange(revert []*types.TipSet, apply []*types.TipSet)
744
745
}
745
746
}
746
747
748
+ var merr error
749
+
747
750
for _ , ts := range revert {
748
751
pts , err := mp .api .LoadTipSet (ts .Parents ())
749
752
if err != nil {
750
- return err
753
+ log .Errorf ("error loading reverted tipset parent: %s" , err )
754
+ merr = multierror .Append (merr , err )
755
+ continue
751
756
}
752
757
758
+ mp .curTs = pts
759
+
753
760
msgs , err := mp .MessagesForBlocks (ts .Blocks ())
754
761
if err != nil {
755
- return err
762
+ log .Errorf ("error retrieving messages for reverted block: %s" , err )
763
+ merr = multierror .Append (merr , err )
764
+ continue
756
765
}
757
766
758
- mp .curTs = pts
759
-
760
767
for _ , msg := range msgs {
761
768
add (msg )
762
769
}
763
770
}
764
771
765
772
for _ , ts := range apply {
773
+ mp .curTs = ts
774
+
766
775
for _ , b := range ts .Blocks () {
767
776
bmsgs , smsgs , err := mp .api .MessagesForBlock (b )
768
777
if err != nil {
769
- return xerrors .Errorf ("failed to get messages for apply block %s(height %d) (msgroot = %s): %w" , b .Cid (), b .Height , b .Messages , err )
778
+ xerr := xerrors .Errorf ("failed to get messages for apply block %s(height %d) (msgroot = %s): %w" , b .Cid (), b .Height , b .Messages , err )
779
+ log .Errorf ("error retrieving messages for block: %s" , xerr )
780
+ merr = multierror .Append (merr , xerr )
781
+ continue
770
782
}
783
+
771
784
for _ , msg := range smsgs {
772
785
rm (msg .Message .From , msg .Message .Nonce )
773
786
maybeRepub (msg .Cid ())
@@ -778,8 +791,6 @@ func (mp *MessagePool) HeadChange(revert []*types.TipSet, apply []*types.TipSet)
778
791
maybeRepub (msg .Cid ())
779
792
}
780
793
}
781
-
782
- mp .curTs = ts
783
794
}
784
795
785
796
if repubTrigger {
@@ -862,7 +873,7 @@ func (mp *MessagePool) HeadChange(revert []*types.TipSet, apply []*types.TipSet)
862
873
}
863
874
}
864
875
865
- return nil
876
+ return merr
866
877
}
867
878
868
879
type statBucket struct {
@@ -962,3 +973,40 @@ func (mp *MessagePool) loadLocal() error {
962
973
963
974
return nil
964
975
}
976
+
977
+ func (mp * MessagePool ) Clear (local bool ) {
978
+ mp .lk .Lock ()
979
+ defer mp .lk .Unlock ()
980
+
981
+ // remove everything if local is true, including removing local messages from
982
+ // the datastore
983
+ if local {
984
+ for a := range mp .localAddrs {
985
+ mset , ok := mp .pending [a ]
986
+ if ! ok {
987
+ continue
988
+ }
989
+
990
+ for _ , m := range mset .msgs {
991
+ err := mp .localMsgs .Delete (datastore .NewKey (string (m .Cid ().Bytes ())))
992
+ if err != nil {
993
+ log .Warnf ("error deleting local message: %s" , err )
994
+ }
995
+ }
996
+ }
997
+
998
+ mp .pending = make (map [address.Address ]* msgSet )
999
+ mp .republished = nil
1000
+
1001
+ return
1002
+ }
1003
+
1004
+ // remove everything except the local messages
1005
+ for a := range mp .pending {
1006
+ _ , isLocal := mp .localAddrs [a ]
1007
+ if isLocal {
1008
+ continue
1009
+ }
1010
+ delete (mp .pending , a )
1011
+ }
1012
+ }
0 commit comments