provide msg length to vm::ApplyMessage

This commit is contained in:
Aayush Rajasekaran 2020-03-25 07:29:35 -04:00
parent c951e0cc83
commit ebcefa80e3
8 changed files with 34 additions and 11 deletions

View File

@ -166,7 +166,7 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, pstate cid.Cid, bms []B
if _, found := processedMsgs[m.Cid()]; found {
continue
}
r, err := vmi.ApplyMessage(ctx, m)
r, err := vmi.ApplyMessage(ctx, m, cm.ChainLength())
if err != nil {
return cid.Undef, cid.Undef, err
}

View File

@ -330,7 +330,8 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch,
}
for i, msg := range msgs {
ret, err := vmi.ApplyMessage(ctx, msg)
// TODO: Use the signed message length for secp messages
ret, err := vmi.ApplyMessage(ctx, msg, msg.ChainLength())
if err != nil {
return cid.Undef, nil, xerrors.Errorf("applying message %s: %w", msg.Cid(), err)
}

View File

@ -654,6 +654,7 @@ type ChainMsg interface {
Cid() cid.Cid
VMMessage() *types.Message
ToStorageBlock() (block.Block, error)
ChainLength() int
}
func (cs *ChainStore) MessagesForTipset(ts *types.TipSet) ([]ChainMsg, error) {

View File

@ -95,7 +95,8 @@ func (cs *ChainStore) call(ctx context.Context, msg *types.Message, ts *types.Ti
msg.Nonce = fromActor.Nonce
// TODO: maybe just use the invoker directly?
ret, err := vmi.ApplyMessage(ctx, msg)
// TODO: use signed message length for secp messages
ret, err := vmi.ApplyMessage(ctx, msg, msg.ChainLength())
if err != nil {
return nil, xerrors.Errorf("apply message failed: %w", err)
}

View File

@ -60,6 +60,14 @@ func (m *Message) Serialize() ([]byte, error) {
return buf.Bytes(), nil
}
func (m *Message) ChainLength() int {
ser, err := m.Serialize()
if err != nil {
panic(err)
}
return len(ser)
}
func (m *Message) ToStorageBlock() (block.Block, error) {
data, err := m.Serialize()
if err != nil {

View File

@ -63,6 +63,14 @@ func (sm *SignedMessage) Serialize() ([]byte, error) {
return buf.Bytes(), nil
}
func (m *SignedMessage) ChainLength() int {
ser, err := m.Serialize()
if err != nil {
panic(err)
}
return len(ser)
}
func (sm *SignedMessage) Size() int {
serdata, err := sm.Serialize()
if err != nil {

View File

@ -41,7 +41,8 @@ func (a *Applier) ApplyMessage(eCtx *vtypes.ExecutionContext, state vstate.VMWra
return vtypes.MessageReceipt{}, err
}
ret, err := lotusVM.ApplyMessage(ctx, toLotusMsg(message))
lm := toLotusMsg(message)
ret, err := lotusVM.ApplyMessage(ctx, toLotusMsg(message), lm.ChainLength())
if err != nil {
return vtypes.MessageReceipt{}, err
}
@ -82,7 +83,7 @@ func (a *Applier) ApplyTipSetMessages(state vstate.VMWrapper, blocks []vtypes.Bl
}
for _, m := range b.SECPMessages {
bm.SecpkMessages = append(bm.SecpkMessages, toLotusMsg(&m.Message))
bm.SecpkMessages = append(bm.SecpkMessages, toLotusSignedMsg(m))
}
bms = append(bms, bm)
@ -145,3 +146,10 @@ func toLotusMsg(msg *vtypes.Message) *types.Message {
Params: msg.Params,
}
}
func toLotusSignedMsg(msg *vtypes.SignedMessage) *types.SignedMessage {
return &types.SignedMessage{
Message: *toLotusMsg(&msg.Message),
Signature: msg.Signature,
}
}

View File

@ -275,7 +275,7 @@ func (vm *VM) ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*Ap
}, actorErr
}
func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error) {
func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message, chainLen int) (*ApplyRet, error) {
ctx, span := trace.StartSpan(ctx, "vm.ApplyMessage")
defer span.End()
if span.IsRecordingEvents() {
@ -291,11 +291,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
}
pl := PricelistByEpoch(vm.blockHeight)
serMsg, err := msg.Serialize()
if err != nil {
return nil, xerrors.Errorf("could not serialize message: %w", err)
}
msgGasCost := pl.OnChainMessage(len(serMsg))
msgGasCost := pl.OnChainMessage(chainLen)
// TODO: charge miner??
if msgGasCost > msg.GasLimit {
return &ApplyRet{