2019-10-17 04:53:25 +00:00
|
|
|
package validation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-02-10 19:16:36 +00:00
|
|
|
|
|
|
|
"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-10 19:16:36 +00:00
|
|
|
|
2020-01-13 20:47:27 +00:00
|
|
|
"github.com/filecoin-project/go-sectorbuilder"
|
2019-10-17 04:53:25 +00:00
|
|
|
|
|
|
|
vchain "github.com/filecoin-project/chain-validation/pkg/chain"
|
|
|
|
vstate "github.com/filecoin-project/chain-validation/pkg/state"
|
2019-11-26 21:58:43 +00:00
|
|
|
vtypes "github.com/filecoin-project/chain-validation/pkg/state/types"
|
2019-10-17 04:53:25 +00:00
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2019-10-17 04:53:25 +00:00
|
|
|
"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 {
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ vchain.Applier = &Applier{}
|
|
|
|
|
|
|
|
func NewApplier() *Applier {
|
|
|
|
return &Applier{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Applier) ApplyMessage(eCtx *vchain.ExecutionContext, state vstate.Wrapper, message interface{}) (vchain.MessageReceipt, error) {
|
|
|
|
ctx := context.TODO()
|
|
|
|
st := state.(*StateWrapper)
|
|
|
|
|
|
|
|
base := st.Cid()
|
|
|
|
randSrc := &vmRand{eCtx}
|
2019-11-26 21:58:43 +00:00
|
|
|
minerAddr, err := address.NewFromBytes(eCtx.MinerOwner.Bytes())
|
2019-10-17 04:53:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return vchain.MessageReceipt{}, err
|
|
|
|
}
|
2020-02-10 19:16:36 +00:00
|
|
|
lotusVM, err := vm.NewVM(base, abi.ChainEpoch(eCtx.Epoch), randSrc, minerAddr, st.bs, vm.Syscalls(sectorbuilder.ProofVerifier))
|
2019-10-17 04:53:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return vchain.MessageReceipt{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ret, err := lotusVM.ApplyMessage(ctx, message.(*types.Message))
|
|
|
|
if err != nil {
|
|
|
|
return vchain.MessageReceipt{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
st.stateRoot, err = lotusVM.Flush(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return vchain.MessageReceipt{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
mr := vchain.MessageReceipt{
|
|
|
|
ExitCode: ret.ExitCode,
|
|
|
|
ReturnValue: ret.Return,
|
2019-11-26 21:58:43 +00:00
|
|
|
GasUsed: vtypes.GasUnit(ret.GasUsed.Uint64()),
|
2019-10-17 04:53:25 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 21:58:43 +00:00
|
|
|
return mr, ret.ActorErr
|
2019-10-17 04:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type vmRand struct {
|
|
|
|
eCtx *vchain.ExecutionContext
|
|
|
|
}
|
|
|
|
|
2020-02-27 00:42:39 +00:00
|
|
|
func (*vmRand) GetRandomness(ctx context.Context, dst crypto.DomainSeparationTag, h int64, input []byte) ([]byte, error) {
|
2019-10-17 04:53:25 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|