Make MpoolPushMessage message wait for the first message to be done

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-08-08 18:56:33 +02:00
parent ae1ae58dd7
commit ed2778f785
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
3 changed files with 27 additions and 4 deletions

View File

@ -29,12 +29,12 @@ func ComputeGasOverestimationBurn(gasUsed, gasLimit int64) (int64, int64) {
return 0, gasLimit return 0, gasLimit
} }
// over = gasLimit/gasUsed - 1 - 0.3 // over = gasLimit/gasUsed - 1 - 0.1
// over = min(over, 1) // over = min(over, 1)
// gasToBurn = (gasLimit - gasUsed) * over // gasToBurn = (gasLimit - gasUsed) * over
// so to factor out division from `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 // gasToBurn = ((gasLimit - gasUsed)*over*gasUsed) / gasUsed
over := gasLimit - (gasOveruseNum*gasUsed)/gasOveruseDenom over := gasLimit - (gasOveruseNum*gasUsed)/gasOveruseDenom
if over < 0 { if over < 0 {

View File

@ -153,6 +153,7 @@ func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message,
for _, m := range pending { for _, m := range pending {
priorMsgs = append(priorMsgs, m) priorMsgs = append(priorMsgs, m)
} }
log.Warnf("added %d prior msgs")
res, err := a.Stmgr.CallWithGas(ctx, &msg, priorMsgs, ts) res, err := a.Stmgr.CallWithGas(ctx, &msg, priorMsgs, ts)
if err != nil { if err != nil {

View File

@ -2,6 +2,7 @@ package full
import ( import (
"context" "context"
"sync"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"go.uber.org/fx" "go.uber.org/fx"
@ -23,6 +24,11 @@ type MpoolAPI struct {
Chain *store.ChainStore Chain *store.ChainStore
Mpool *messagepool.MessagePool 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) { 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) 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) { 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 { if msg.Nonce != 0 {
return nil, xerrors.Errorf("MpoolPushMessage expects message nonce to be 0, was %d", msg.Nonce) return nil, xerrors.Errorf("MpoolPushMessage expects message nonce to be 0, was %d", msg.Nonce)
} }