Wire in context to VMContext
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
c92e9103d4
commit
0e35240fe9
@ -21,7 +21,7 @@ func miningRewardForBlock(base *types.TipSet) types.BigInt {
|
|||||||
return types.NewInt(10000)
|
return types.NewInt(10000)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MinerCreateBlock(cs *store.ChainStore, miner address.Address, parents *types.TipSet, tickets []types.Ticket, proof types.ElectionProof, msgs []*types.SignedMessage) (*types.FullBlock, error) {
|
func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.Address, parents *types.TipSet, tickets []types.Ticket, proof types.ElectionProof, msgs []*types.SignedMessage) (*types.FullBlock, error) {
|
||||||
st, err := cs.TipSetState(parents.Cids())
|
st, err := cs.TipSetState(parents.Cids())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to load tipset state")
|
return nil, errors.Wrap(err, "failed to load tipset state")
|
||||||
@ -63,7 +63,7 @@ func MinerCreateBlock(cs *store.ChainStore, miner address.Address, parents *type
|
|||||||
} else {
|
} else {
|
||||||
msgCids = append(msgCids, msg.Cid())
|
msgCids = append(msgCids, msg.Cid())
|
||||||
}
|
}
|
||||||
rec, err := vm.ApplyMessage(&msg.Message)
|
rec, err := vm.ApplyMessage(ctx, &msg.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "apply message failure")
|
return nil, errors.Wrap(err, "apply message failure")
|
||||||
}
|
}
|
||||||
|
@ -298,7 +298,7 @@ func (syncer *Syncer) SyncBootstrap() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := syncer.ValidateTipSet(fts); err != nil {
|
if err := syncer.ValidateTipSet(context.TODO(), fts); err != nil {
|
||||||
log.Errorf("failed to validate tipset: %s", err)
|
log.Errorf("failed to validate tipset: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -482,7 +482,7 @@ func (syncer *Syncer) SyncCaughtUp(maybeHead *store.FullTipSet) error {
|
|||||||
|
|
||||||
for i := len(chain) - 1; i >= 0; i-- {
|
for i := len(chain) - 1; i >= 0; i-- {
|
||||||
ts := chain[i]
|
ts := chain[i]
|
||||||
if err := syncer.ValidateTipSet(ts); err != nil {
|
if err := syncer.ValidateTipSet(context.TODO(), ts); err != nil {
|
||||||
return errors.Wrap(err, "validate tipset failed")
|
return errors.Wrap(err, "validate tipset failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,21 +500,21 @@ func (syncer *Syncer) SyncCaughtUp(maybeHead *store.FullTipSet) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (syncer *Syncer) ValidateTipSet(fts *store.FullTipSet) error {
|
func (syncer *Syncer) ValidateTipSet(ctx context.Context, fts *store.FullTipSet) error {
|
||||||
ts := fts.TipSet()
|
ts := fts.TipSet()
|
||||||
if ts.Equals(syncer.Genesis) {
|
if ts.Equals(syncer.Genesis) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, b := range fts.Blocks {
|
for _, b := range fts.Blocks {
|
||||||
if err := syncer.ValidateBlock(b); err != nil {
|
if err := syncer.ValidateBlock(ctx, b); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (syncer *Syncer) ValidateBlock(b *types.FullBlock) error {
|
func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) error {
|
||||||
h := b.Header
|
h := b.Header
|
||||||
stateroot, err := syncer.store.TipSetState(h.Parents)
|
stateroot, err := syncer.store.TipSetState(h.Parents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -537,7 +537,7 @@ func (syncer *Syncer) ValidateBlock(b *types.FullBlock) error {
|
|||||||
|
|
||||||
var receipts []interface{}
|
var receipts []interface{}
|
||||||
for _, m := range b.Messages {
|
for _, m := range b.Messages {
|
||||||
receipt, err := vm.ApplyMessage(&m.Message)
|
receipt, err := vm.ApplyMessage(ctx, &m.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,22 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/chain/store"
|
"github.com/filecoin-project/go-lotus/chain/store"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
"github.com/filecoin-project/go-lotus/lib/bufbstore"
|
"github.com/filecoin-project/go-lotus/lib/bufbstore"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
|
||||||
bserv "github.com/ipfs/go-blockservice"
|
bserv "github.com/ipfs/go-blockservice"
|
||||||
cid "github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
hamt "github.com/ipfs/go-hamt-ipld"
|
hamt "github.com/ipfs/go-hamt-ipld"
|
||||||
ipld "github.com/ipfs/go-ipld-format"
|
ipld "github.com/ipfs/go-ipld-format"
|
||||||
|
logging "github.com/ipfs/go-log"
|
||||||
dag "github.com/ipfs/go-merkledag"
|
dag "github.com/ipfs/go-merkledag"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log = logging.Logger("vm")
|
||||||
|
|
||||||
type VMContext struct {
|
type VMContext struct {
|
||||||
|
ctx context.Context
|
||||||
|
|
||||||
vm *VM
|
vm *VM
|
||||||
state *state.StateTree
|
state *state.StateTree
|
||||||
msg *types.Message
|
msg *types.Message
|
||||||
@ -88,6 +94,15 @@ func (vmc *VMContext) Origin() address.Address {
|
|||||||
|
|
||||||
// Send allows the current execution context to invoke methods on other actors in the system
|
// Send allows the current execution context to invoke methods on other actors in the system
|
||||||
func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt, params []byte) ([]byte, aerrors.ActorError) {
|
func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt, params []byte) ([]byte, aerrors.ActorError) {
|
||||||
|
ctx, span := trace.StartSpan(vmc.ctx, "vm.send")
|
||||||
|
defer span.End()
|
||||||
|
if span.IsRecordingEvents() {
|
||||||
|
span.AddAttributes(
|
||||||
|
trace.StringAttribute("to", to.String()),
|
||||||
|
trace.Int64Attribute("method", int64(method)),
|
||||||
|
trace.StringAttribute("value", value.String()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
msg := &types.Message{
|
msg := &types.Message{
|
||||||
From: vmc.msg.To,
|
From: vmc.msg.To,
|
||||||
@ -102,7 +117,7 @@ func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt
|
|||||||
return nil, aerrors.Absorb(err, 2, "could not find actor for Send")
|
return nil, aerrors.Absorb(err, 2, "could not find actor for Send")
|
||||||
}
|
}
|
||||||
|
|
||||||
nvmctx := vmc.vm.makeVMContext(toAct.Head, vmc.origin, msg)
|
nvmctx := vmc.vm.makeVMContext(ctx, toAct.Head, vmc.origin, msg)
|
||||||
|
|
||||||
res, aerr := vmc.vm.Invoke(toAct, nvmctx, method, params)
|
res, aerr := vmc.vm.Invoke(toAct, nvmctx, method, params)
|
||||||
if aerr != nil {
|
if aerr != nil {
|
||||||
@ -135,9 +150,10 @@ func (vmctx *VMContext) VerifySignature(sig types.Signature, act address.Address
|
|||||||
panic("NYI")
|
panic("NYI")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vm *VM) makeVMContext(sroot cid.Cid, origin address.Address, msg *types.Message) *VMContext {
|
func (vm *VM) makeVMContext(ctx context.Context, sroot cid.Cid, origin address.Address, msg *types.Message) *VMContext {
|
||||||
|
|
||||||
return &VMContext{
|
return &VMContext{
|
||||||
|
ctx: ctx,
|
||||||
vm: vm,
|
vm: vm,
|
||||||
state: vm.cstate,
|
state: vm.cstate,
|
||||||
sroot: sroot,
|
sroot: sroot,
|
||||||
@ -183,7 +199,10 @@ func NewVM(base cid.Cid, height uint64, maddr address.Address, cs *store.ChainSt
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vm *VM) ApplyMessage(msg *types.Message) (*types.MessageReceipt, error) {
|
func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*types.MessageReceipt, error) {
|
||||||
|
ctx, span := trace.StartSpan(ctx, "vm.ApplyMessage")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
st := vm.cstate
|
st := vm.cstate
|
||||||
st.Snapshot()
|
st.Snapshot()
|
||||||
fromActor, err := st.GetActor(msg.From)
|
fromActor, err := st.GetActor(msg.From)
|
||||||
@ -220,7 +239,7 @@ func (vm *VM) ApplyMessage(msg *types.Message) (*types.MessageReceipt, error) {
|
|||||||
}
|
}
|
||||||
DepositFunds(toActor, msg.Value)
|
DepositFunds(toActor, msg.Value)
|
||||||
|
|
||||||
vmctx := vm.makeVMContext(toActor.Head, msg.From, msg)
|
vmctx := vm.makeVMContext(ctx, toActor.Head, msg.From, msg)
|
||||||
|
|
||||||
var errcode byte
|
var errcode byte
|
||||||
var ret []byte
|
var ret []byte
|
||||||
@ -336,6 +355,13 @@ func (vm *VM) TransferFunds(from, to address.Address, amt types.BigInt) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (vm *VM) Invoke(act *types.Actor, vmctx *VMContext, method uint64, params []byte) ([]byte, aerrors.ActorError) {
|
func (vm *VM) Invoke(act *types.Actor, vmctx *VMContext, method uint64, params []byte) ([]byte, aerrors.ActorError) {
|
||||||
|
ctx, span := trace.StartSpan(vmctx.ctx, "vm.Invoke")
|
||||||
|
defer span.End()
|
||||||
|
var oldCtx context.Context
|
||||||
|
oldCtx, vmctx.ctx = vmctx.ctx, ctx
|
||||||
|
defer func() {
|
||||||
|
vmctx.ctx = oldCtx
|
||||||
|
}()
|
||||||
ret, err := vm.inv.Invoke(act, vmctx, method, params)
|
ret, err := vm.inv.Invoke(act, vmctx, method, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -4,10 +4,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
"gopkg.in/urfave/cli.v2"
|
"gopkg.in/urfave/cli.v2"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/build"
|
"github.com/filecoin-project/go-lotus/build"
|
||||||
lcli "github.com/filecoin-project/go-lotus/cli"
|
lcli "github.com/filecoin-project/go-lotus/cli"
|
||||||
|
"github.com/filecoin-project/go-lotus/tracing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Logger("main")
|
var log = logging.Logger("main")
|
||||||
@ -20,6 +22,26 @@ func main() {
|
|||||||
runCmd,
|
runCmd,
|
||||||
initCmd,
|
initCmd,
|
||||||
}
|
}
|
||||||
|
jaeger := tracing.SetupJaegerTracing("lotus")
|
||||||
|
defer func() {
|
||||||
|
if jaeger != nil {
|
||||||
|
jaeger.Flush()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for _, cmd := range local {
|
||||||
|
cmd := cmd
|
||||||
|
originBefore := cmd.Before
|
||||||
|
cmd.Before = func(cctx *cli.Context) error {
|
||||||
|
trace.UnregisterExporter(jaeger)
|
||||||
|
jaeger = tracing.SetupJaegerTracing("lotus/" + cmd.Name)
|
||||||
|
|
||||||
|
if originBefore != nil {
|
||||||
|
return originBefore(cctx)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "lotus-storage-miner",
|
Name: "lotus-storage-miner",
|
||||||
|
2
go.sum
2
go.sum
@ -384,8 +384,10 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
|
|||||||
github.com/marten-seemann/qtls v0.2.3 h1:0yWJ43C62LsZt08vuQJDK1uC1czUc3FJeCLPoNAI4vA=
|
github.com/marten-seemann/qtls v0.2.3 h1:0yWJ43C62LsZt08vuQJDK1uC1czUc3FJeCLPoNAI4vA=
|
||||||
github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
|
github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
|
||||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||||
|
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
|
||||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
|
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
|
||||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
github.com/miekg/dns v1.1.4/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.1.4/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
|
||||||
chain "github.com/filecoin-project/go-lotus/chain"
|
chain "github.com/filecoin-project/go-lotus/chain"
|
||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
@ -57,6 +58,8 @@ type Miner struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Miner) Mine(ctx context.Context) {
|
func (m *Miner) Mine(ctx context.Context) {
|
||||||
|
ctx, span := trace.StartSpan(ctx, "/mine")
|
||||||
|
defer span.End()
|
||||||
for {
|
for {
|
||||||
base, err := m.GetBestMiningCandidate()
|
base, err := m.GetBestMiningCandidate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -100,7 +100,7 @@ func (a *FullNodeAPI) MinerStart(ctx context.Context, addr address.Address) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *FullNodeAPI) MinerCreateBlock(ctx context.Context, addr address.Address, parents *types.TipSet, tickets []types.Ticket, proof types.ElectionProof, msgs []*types.SignedMessage) (*chain.BlockMsg, error) {
|
func (a *FullNodeAPI) MinerCreateBlock(ctx context.Context, addr address.Address, parents *types.TipSet, tickets []types.Ticket, proof types.ElectionProof, msgs []*types.SignedMessage) (*chain.BlockMsg, error) {
|
||||||
fblk, err := chain.MinerCreateBlock(a.Chain, addr, parents, tickets, proof, msgs)
|
fblk, err := chain.MinerCreateBlock(ctx, a.Chain, addr, parents, tickets, proof, msgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user