Apply sequence of messages
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
7d83349507
commit
629e03f303
@ -617,6 +617,14 @@ func (mp *MessagePool) Pending() ([]*types.SignedMessage, *types.TipSet) {
|
|||||||
|
|
||||||
return out, mp.curTs
|
return out, mp.curTs
|
||||||
}
|
}
|
||||||
|
func (mp *MessagePool) PendingFor(a address.Address) ([]*types.SignedMessage, *types.TipSet) {
|
||||||
|
mp.curTsLk.Lock()
|
||||||
|
defer mp.curTsLk.Unlock()
|
||||||
|
|
||||||
|
mp.lk.Lock()
|
||||||
|
defer mp.lk.Unlock()
|
||||||
|
return mp.pendingFor(a), mp.curTs
|
||||||
|
}
|
||||||
|
|
||||||
func (mp *MessagePool) pendingFor(a address.Address) []*types.SignedMessage {
|
func (mp *MessagePool) pendingFor(a address.Address) []*types.SignedMessage {
|
||||||
mset := mp.pending[a]
|
mset := mp.pending[a]
|
||||||
|
@ -86,7 +86,7 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.
|
|||||||
return sm.CallRaw(ctx, msg, state, r, ts.Height())
|
return sm.CallRaw(ctx, msg, state, r, ts.Height())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, ts *types.TipSet) (*api.InvocResult, error) {
|
func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet) (*api.InvocResult, error) {
|
||||||
ctx, span := trace.StartSpan(ctx, "statemanager.CallWithGas")
|
ctx, span := trace.StartSpan(ctx, "statemanager.CallWithGas")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
@ -110,6 +110,13 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, ts
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to set up vm: %w", err)
|
return nil, xerrors.Errorf("failed to set up vm: %w", err)
|
||||||
}
|
}
|
||||||
|
for i, m := range priorMsgs {
|
||||||
|
_, err := vmi.ApplyMessage(ctx, m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("applying prior message (%d, %s): %w", i, m.Cid(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fromActor, err := vmi.StateTree().GetActor(msg.From)
|
fromActor, err := vmi.StateTree().GetActor(msg.From)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("call raw get actor: %s", err)
|
return nil, xerrors.Errorf("call raw get actor: %s", err)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/messagepool"
|
||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
@ -17,6 +18,7 @@ type GasAPI struct {
|
|||||||
fx.In
|
fx.In
|
||||||
Stmgr *stmgr.StateManager
|
Stmgr *stmgr.StateManager
|
||||||
Cs *store.ChainStore
|
Cs *store.ChainStore
|
||||||
|
Mpool *messagepool.MessagePool
|
||||||
}
|
}
|
||||||
|
|
||||||
const MinGasPrice = 1
|
const MinGasPrice = 1
|
||||||
@ -35,19 +37,25 @@ func (a *GasAPI) GasEstimateGasPrice(ctx context.Context, nblocksincl uint64,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message,
|
func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, _ types.TipSetKey) (int64, error) {
|
||||||
tsk types.TipSetKey) (int64, error) {
|
|
||||||
|
|
||||||
msg := *msgIn
|
msg := *msgIn
|
||||||
msg.GasLimit = build.BlockGasLimit
|
msg.GasLimit = build.BlockGasLimit
|
||||||
msg.GasPrice = types.NewInt(1)
|
msg.GasPrice = types.NewInt(1)
|
||||||
|
|
||||||
ts, err := a.Cs.GetTipSetFromKey(tsk)
|
currTs := a.Cs.GetHeaviestTipSet()
|
||||||
|
fromA, err := a.Stmgr.ResolveToKeyAddress(ctx, msgIn.From, currTs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, xerrors.Errorf("could not get tipset: %w", err)
|
return -1, xerrors.Errorf("getting key address: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := a.Stmgr.CallWithGas(ctx, &msg, ts)
|
pending, ts := a.Mpool.PendingFor(fromA)
|
||||||
|
priorMsgs := make([]types.ChainMsg, 0, len(pending))
|
||||||
|
for _, m := range pending {
|
||||||
|
priorMsgs = append(priorMsgs, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := a.Stmgr.CallWithGas(ctx, &msg, priorMsgs, ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, xerrors.Errorf("CallWithGas failed: %w", err)
|
return -1, xerrors.Errorf("CallWithGas failed: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user