lotus/chain/validation/applier.go

86 lines
2.2 KiB
Go
Raw Normal View History

package validation
import (
"context"
"github.com/filecoin-project/specs-actors/actors/abi"
2020-02-27 00:42:39 +00:00
"github.com/filecoin-project/specs-actors/actors/crypto"
2020-02-27 22:17:08 +00:00
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
2020-01-13 20:47:27 +00:00
"github.com/filecoin-project/go-sectorbuilder"
2020-02-27 22:17:08 +00:00
vtypes "github.com/filecoin-project/chain-validation/chain/types"
vstate "github.com/filecoin-project/chain-validation/state"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
)
// Applier applies messages to state trees and storage.
type Applier struct {
}
2020-02-27 22:17:08 +00:00
var _ vstate.Applier = &Applier{}
func NewApplier() *Applier {
return &Applier{}
}
2020-02-27 22:17:08 +00:00
func (a *Applier) ApplyMessage(eCtx *vtypes.ExecutionContext, state vstate.VMWrapper, message *vtypes.Message) (vtypes.MessageReceipt, error) {
ctx := context.TODO()
st := state.(*StateWrapper)
2020-02-27 22:17:08 +00:00
base := st.Root()
randSrc := &vmRand{eCtx}
2020-02-27 22:17:08 +00:00
lotusVM, err := vm.NewVM(base, abi.ChainEpoch(eCtx.Epoch), randSrc, eCtx.Miner, st.bs, vm.Syscalls(sectorbuilder.ProofVerifier))
if err != nil {
2020-02-27 22:17:08 +00:00
return vtypes.MessageReceipt{}, err
}
2020-02-27 22:17:08 +00:00
ret, err := lotusVM.ApplyMessage(ctx, toLotusMsg(message))
if err != nil {
2020-02-27 22:17:08 +00:00
return vtypes.MessageReceipt{}, err
}
st.stateRoot, err = lotusVM.Flush(ctx)
if err != nil {
2020-02-27 22:17:08 +00:00
return vtypes.MessageReceipt{}, err
}
2020-02-27 22:17:08 +00:00
mr := vtypes.MessageReceipt{
ExitCode: exitcode.ExitCode(ret.ExitCode),
ReturnValue: ret.Return,
2020-02-27 22:17:08 +00:00
GasUsed: ret.GasUsed,
}
return mr, nil
}
2020-02-27 22:17:08 +00:00
func (a *Applier) ApplyTipSetMessages(state vstate.VMWrapper, blocks []vtypes.BlockMessagesInfo, epoch abi.ChainEpoch, rnd vstate.RandomnessSource) ([]vtypes.MessageReceipt, error) {
panic("implement me")
}
type vmRand struct {
2020-02-27 22:17:08 +00:00
eCtx *vtypes.ExecutionContext
}
2020-02-27 00:42:39 +00:00
func (*vmRand) GetRandomness(ctx context.Context, dst crypto.DomainSeparationTag, h int64, input []byte) ([]byte, error) {
panic("implement me")
}
2020-02-27 22:17:08 +00:00
func toLotusMsg(msg *vtypes.Message) *types.Message {
return &types.Message{
To: msg.To,
From: msg.From,
Nonce: uint64(msg.CallSeqNum),
Method: msg.Method,
Value: types.BigInt{msg.Value.Int},
GasPrice: types.BigInt{msg.GasPrice.Int},
GasLimit: types.NewInt(uint64(msg.GasLimit)),
Params: msg.Params,
}
}