rate limit messages per actor by enforcing maximum pending message limit

This commit is contained in:
vyzo 2020-08-26 22:40:10 +03:00
parent d3e95d6b77
commit ad889a7240

View File

@ -50,6 +50,8 @@ var RepublishInterval = pubsub.TimeCacheDuration + time.Duration(5*build.BlockDe
var minimumBaseFee = types.NewInt(uint64(build.MinimumBaseFee))
var MaxActorPendingMessages = 1000
var (
ErrMessageTooBig = errors.New("message too big")
@ -162,6 +164,11 @@ func (ms *msgSet) add(m *types.SignedMessage, mp *MessagePool) (bool, error) {
//ms.requiredFunds.Sub(ms.requiredFunds, exms.Message.Value.Int)
}
if !has && len(ms.msgs) > MaxActorPendingMessages {
return false, xerrors.Errorf("too many pending messages for actor in the mpool: %w",
ErrSoftValidationFailure)
}
ms.msgs[m.Message.Nonce] = m
ms.requiredFunds.Add(ms.requiredFunds, m.Message.RequiredFunds().Int)
//ms.requiredFunds.Add(ms.requiredFunds, m.Message.Value.Int)