From a2c0c10d2ae3dcd2b985e9049c1838dc51613c8b Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 26 Aug 2020 15:27:09 +0300 Subject: [PATCH] correctly account for message replacement in required funds tracking --- chain/messagepool/messagepool.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index c5e377d7e..89e454359 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -174,6 +174,18 @@ func (ms *msgSet) rm(nonce uint64) { } } +func (ms *msgSet) getRequiredFunds(nonce uint64) types.BigInt { + m, has := ms.msgs[nonce] + if has { + requiredFunds := new(stdbig.Int).Set(ms.requiredFunds) + requiredFunds.Sub(requiredFunds, m.Message.RequiredFunds().Int) + requiredFunds.Sub(requiredFunds, m.Message.Value.Int) + return types.BigInt{Int: requiredFunds} + } + + return types.BigInt{Int: new(stdbig.Int).Set(ms.requiredFunds)} +} + func New(api Provider, ds dtypes.MetadataDS, netName dtypes.NetworkName) (*MessagePool, error) { cache, _ := lru.New2Q(build.BlsSignatureCacheSize) verifcache, _ := lru.New2Q(build.VerifSigCacheSize) @@ -427,7 +439,7 @@ func (mp *MessagePool) checkBalance(m *types.SignedMessage, curTs *types.TipSet) mset, ok := mp.pending[m.Message.From] if ok { - requiredFunds = types.BigAdd(requiredFunds, types.BigInt{Int: mset.requiredFunds}) + requiredFunds = types.BigAdd(requiredFunds, mset.getRequiredFunds(m.Message.Nonce)) } if balance.LessThan(requiredFunds) {