From ed2778f785ae09d94097bdf6ffff735b35505452 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Sat, 8 Aug 2020 18:56:33 +0200 Subject: [PATCH] Make MpoolPushMessage message wait for the first message to be done Signed-off-by: Jakub Sztandera --- chain/vm/burn.go | 4 ++-- node/impl/full/gas.go | 1 + node/impl/full/mpool.go | 26 ++++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/chain/vm/burn.go b/chain/vm/burn.go index bad132de9..e9b6802c1 100644 --- a/chain/vm/burn.go +++ b/chain/vm/burn.go @@ -29,12 +29,12 @@ func ComputeGasOverestimationBurn(gasUsed, gasLimit int64) (int64, int64) { return 0, gasLimit } - // over = gasLimit/gasUsed - 1 - 0.3 + // over = gasLimit/gasUsed - 1 - 0.1 // over = min(over, 1) // gasToBurn = (gasLimit - gasUsed) * over // so to factor out division from `over` - // over*gasUsed = min(gasLimit - (13*gasUsed)/10, gasUsed) + // over*gasUsed = min(gasLimit - (11*gasUsed)/10, gasUsed) // gasToBurn = ((gasLimit - gasUsed)*over*gasUsed) / gasUsed over := gasLimit - (gasOveruseNum*gasUsed)/gasOveruseDenom if over < 0 { diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index c14c147a0..243c97e68 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -153,6 +153,7 @@ func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, for _, m := range pending { priorMsgs = append(priorMsgs, m) } + log.Warnf("added %d prior msgs") res, err := a.Stmgr.CallWithGas(ctx, &msg, priorMsgs, ts) if err != nil { diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index 3d2e7cfd2..6c9e65ef6 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -2,6 +2,7 @@ package full import ( "context" + "sync" "github.com/ipfs/go-cid" "go.uber.org/fx" @@ -23,6 +24,11 @@ type MpoolAPI struct { Chain *store.ChainStore Mpool *messagepool.MessagePool + + PushLocks struct { + m map[address.Address]chan struct{} + sync.Mutex + } `name:"verymuchunique" optional:"true"` } func (a *MpoolAPI) MpoolGetConfig(context.Context) (*types.MpoolConfig, error) { @@ -105,9 +111,25 @@ func (a *MpoolAPI) MpoolPush(ctx context.Context, smsg *types.SignedMessage) (ci return a.Mpool.Push(smsg) } -// GasMargin sets by how much should gas used be increased over test execution - func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*types.SignedMessage, error) { + { + a.PushLocks.Lock() + if a.PushLocks.m == nil { + a.PushLocks.m = make(map[address.Address]chan struct{}) + } + lk, ok := a.PushLocks.m[msg.From] + if !ok { + lk = make(chan struct{}, 1) + a.PushLocks.m[msg.From] = lk + } + a.PushLocks.Unlock() + + lk <- struct{}{} + defer func() { + <-lk + }() + } + if msg.Nonce != 0 { return nil, xerrors.Errorf("MpoolPushMessage expects message nonce to be 0, was %d", msg.Nonce) }