Merge pull request #1383 from filecoin-project/asr/actoraddress
New Actor Addresses should be generated as per spec
This commit is contained in:
commit
4dfe467e66
@ -41,7 +41,7 @@ func (f *Factories) NewRandomnessSource() vstate.RandomnessSource {
|
|||||||
func (f *Factories) NewValidationConfig() vstate.ValidationConfig {
|
func (f *Factories) NewValidationConfig() vstate.ValidationConfig {
|
||||||
trackGas := false
|
trackGas := false
|
||||||
checkExit := true
|
checkExit := true
|
||||||
checkRet := false // TODO enable return value checking once https://github.com/filecoin-project/specs-actors/pull/230 lands
|
checkRet := true
|
||||||
// ignore gas and return value assertions
|
// ignore gas and return value assertions
|
||||||
return NewConfig(trackGas, checkExit, checkRet)
|
return NewConfig(trackGas, checkExit, checkRet)
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,12 @@ type Runtime struct {
|
|||||||
sys runtime.Syscalls
|
sys runtime.Syscalls
|
||||||
|
|
||||||
// address that started invoke chain
|
// address that started invoke chain
|
||||||
origin address.Address
|
origin address.Address
|
||||||
|
originNonce uint64
|
||||||
|
|
||||||
internalExecutions []*ExecutionResult
|
internalExecutions []*ExecutionResult
|
||||||
|
// the first internal call has a value of 1 for this field
|
||||||
|
internalCallCounter int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) ResolveAddress(address address.Address) (ret address.Address, ok bool) {
|
func (rs *Runtime) ResolveAddress(address address.Address) (ret address.Address, ok bool) {
|
||||||
@ -158,19 +161,14 @@ func (rs *Runtime) Store() vmr.Store {
|
|||||||
|
|
||||||
func (rt *Runtime) NewActorAddress() address.Address {
|
func (rt *Runtime) NewActorAddress() address.Address {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
if err := rt.Message().Caller().MarshalCBOR(&b); err != nil { // todo: spec says cbor; why not just bytes?
|
if err := rt.origin.MarshalCBOR(&b); err != nil { // todo: spec says cbor; why not just bytes?
|
||||||
rt.Abortf(exitcode.ErrSerialization, "writing caller address into a buffer: %v", err)
|
rt.Abortf(exitcode.ErrSerialization, "writing caller address into a buffer: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
act, err := rt.state.GetActor(rt.origin)
|
if err := binary.Write(&b, binary.BigEndian, rt.originNonce); err != nil {
|
||||||
if err != nil {
|
|
||||||
rt.Abortf(exitcode.SysErrInternal, "getting top level actor: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := binary.Write(&b, binary.BigEndian, act.Nonce); err != nil {
|
|
||||||
rt.Abortf(exitcode.ErrSerialization, "writing nonce address into a buffer: %v", err)
|
rt.Abortf(exitcode.ErrSerialization, "writing nonce address into a buffer: %v", err)
|
||||||
}
|
}
|
||||||
if err := binary.Write(&b, binary.BigEndian, uint64(0)); err != nil { // TODO: expose on vm
|
if err := binary.Write(&b, binary.BigEndian, rt.internalCallCounter); err != nil { // TODO: expose on vm
|
||||||
rt.Abortf(exitcode.ErrSerialization, "writing callSeqNum address into a buffer: %v", err)
|
rt.Abortf(exitcode.ErrSerialization, "writing callSeqNum address into a buffer: %v", err)
|
||||||
}
|
}
|
||||||
addr, err := address.NewActorAddress(b.Bytes())
|
addr, err := address.NewActorAddress(b.Bytes())
|
||||||
@ -317,32 +315,34 @@ func (rt *Runtime) internalSend(to address.Address, method abi.MethodNum, value
|
|||||||
}
|
}
|
||||||
defer st.ClearSnapshot()
|
defer st.ClearSnapshot()
|
||||||
|
|
||||||
ret, err, subrt := rt.vm.send(ctx, msg, rt, 0)
|
ret, errSend, subrt := rt.vm.send(ctx, msg, rt, 0)
|
||||||
if err != nil {
|
if errSend != nil {
|
||||||
if err := st.Revert(); err != nil {
|
if errRevert := st.Revert(); errRevert != nil {
|
||||||
return nil, aerrors.Escalate(err, "failed to revert state tree after failed subcall")
|
return nil, aerrors.Escalate(errRevert, "failed to revert state tree after failed subcall")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mr := types.MessageReceipt{
|
mr := types.MessageReceipt{
|
||||||
ExitCode: exitcode.ExitCode(aerrors.RetCode(err)),
|
ExitCode: exitcode.ExitCode(aerrors.RetCode(errSend)),
|
||||||
Return: ret,
|
Return: ret,
|
||||||
GasUsed: types.EmptyInt,
|
GasUsed: types.EmptyInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
var es = ""
|
|
||||||
if err != nil {
|
|
||||||
es = err.Error()
|
|
||||||
}
|
|
||||||
er := ExecutionResult{
|
er := ExecutionResult{
|
||||||
Msg: msg,
|
Msg: msg,
|
||||||
MsgRct: &mr,
|
MsgRct: &mr,
|
||||||
Error: es,
|
|
||||||
Subcalls: subrt.internalExecutions,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if errSend != nil {
|
||||||
|
er.Error = errSend.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
if subrt != nil {
|
||||||
|
er.Subcalls = subrt.internalExecutions
|
||||||
|
rt.internalCallCounter = subrt.internalCallCounter
|
||||||
|
}
|
||||||
rt.internalExecutions = append(rt.internalExecutions, &er)
|
rt.internalExecutions = append(rt.internalExecutions, &er)
|
||||||
return ret, err
|
return ret, errSend
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) State() vmr.StateHandle {
|
func (rs *Runtime) State() vmr.StateHandle {
|
||||||
|
@ -115,18 +115,20 @@ func (bs *gasChargingBlocks) Put(blk block.Block) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin address.Address, usedGas types.BigInt) *Runtime {
|
func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin address.Address, originNonce uint64, usedGas types.BigInt, icc int64) *Runtime {
|
||||||
rt := &Runtime{
|
rt := &Runtime{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
vm: vm,
|
vm: vm,
|
||||||
state: vm.cstate,
|
state: vm.cstate,
|
||||||
msg: msg,
|
msg: msg,
|
||||||
origin: origin,
|
origin: origin,
|
||||||
height: vm.blockHeight,
|
originNonce: originNonce,
|
||||||
sys: vm.Syscalls,
|
height: vm.blockHeight,
|
||||||
|
sys: vm.Syscalls,
|
||||||
|
|
||||||
gasUsed: usedGas,
|
gasUsed: usedGas,
|
||||||
gasAvailable: msg.GasLimit,
|
gasAvailable: msg.GasLimit,
|
||||||
|
internalCallCounter: icc,
|
||||||
}
|
}
|
||||||
rt.cst = &cbor.BasicIpldStore{
|
rt.cst = &cbor.BasicIpldStore{
|
||||||
Blocks: &gasChargingBlocks{rt.ChargeGas, vm.cst.Blocks},
|
Blocks: &gasChargingBlocks{rt.ChargeGas, vm.cst.Blocks},
|
||||||
@ -206,11 +208,15 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
|
|||||||
|
|
||||||
gasUsed := types.NewInt(gasCharge)
|
gasUsed := types.NewInt(gasCharge)
|
||||||
origin := msg.From
|
origin := msg.From
|
||||||
|
on := msg.Nonce
|
||||||
|
var icc int64 = 0
|
||||||
if parent != nil {
|
if parent != nil {
|
||||||
gasUsed = types.BigAdd(parent.gasUsed, gasUsed)
|
gasUsed = types.BigAdd(parent.gasUsed, gasUsed)
|
||||||
origin = parent.origin
|
origin = parent.origin
|
||||||
|
on = parent.originNonce
|
||||||
|
icc = parent.internalCallCounter + 1
|
||||||
}
|
}
|
||||||
rt := vm.makeRuntime(ctx, msg, origin, gasUsed)
|
rt := vm.makeRuntime(ctx, msg, origin, on, gasUsed, icc)
|
||||||
if parent != nil {
|
if parent != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
parent.gasUsed = rt.gasUsed
|
parent.gasUsed = rt.gasUsed
|
||||||
|
2
go.mod
2
go.mod
@ -11,7 +11,7 @@ require (
|
|||||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
||||||
github.com/coreos/go-systemd/v22 v22.0.0
|
github.com/coreos/go-systemd/v22 v22.0.0
|
||||||
github.com/docker/go-units v0.4.0
|
github.com/docker/go-units v0.4.0
|
||||||
github.com/filecoin-project/chain-validation v0.0.6-0.20200311235406-31f0d58e13e4
|
github.com/filecoin-project/chain-validation v0.0.6-0.20200318065243-0ccb5ec3afc5
|
||||||
github.com/filecoin-project/filecoin-ffi v0.0.0-20200304181354-4446ff8a1bb9
|
github.com/filecoin-project/filecoin-ffi v0.0.0-20200304181354-4446ff8a1bb9
|
||||||
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be
|
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be
|
||||||
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e
|
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e
|
||||||
|
4
go.sum
4
go.sum
@ -99,8 +99,8 @@ github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFP
|
|||||||
github.com/fatih/color v1.8.0 h1:5bzFgL+oy7JITMTxUPJ00n7VxmYd/PdMp5mHFX40/RY=
|
github.com/fatih/color v1.8.0 h1:5bzFgL+oy7JITMTxUPJ00n7VxmYd/PdMp5mHFX40/RY=
|
||||||
github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8=
|
github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8=
|
||||||
github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E=
|
github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E=
|
||||||
github.com/filecoin-project/chain-validation v0.0.6-0.20200311235406-31f0d58e13e4 h1:chsO3yHq03hxr5MtB8XTIbTAyu1S6mx9lt2M+0JOhto=
|
github.com/filecoin-project/chain-validation v0.0.6-0.20200318065243-0ccb5ec3afc5 h1:cr9+8iX+u9fDV53MWqqZw820EyeWVX+h/HCz56JUWb0=
|
||||||
github.com/filecoin-project/chain-validation v0.0.6-0.20200311235406-31f0d58e13e4/go.mod h1:7HoEkq8OWN3vGcCZ4SRGxAPeL/mLckS+PNV3F0XmrCs=
|
github.com/filecoin-project/chain-validation v0.0.6-0.20200318065243-0ccb5ec3afc5/go.mod h1:7HoEkq8OWN3vGcCZ4SRGxAPeL/mLckS+PNV3F0XmrCs=
|
||||||
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5 h1:/MmWluswvDIbuPvBct4q6HeQgVm62O2DzWYTB38kt4A=
|
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5 h1:/MmWluswvDIbuPvBct4q6HeQgVm62O2DzWYTB38kt4A=
|
||||||
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
|
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
|
||||||
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be h1:TooKBwR/g8jG0hZ3lqe9S5sy2vTUcLOZLlz3M5wGn2E=
|
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be h1:TooKBwR/g8jG0hZ3lqe9S5sy2vTUcLOZLlz3M5wGn2E=
|
||||||
|
Loading…
Reference in New Issue
Block a user