From ef288b8a6c685eba67c3ea26f3c64af1dac1fdd5 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 20 Mar 2020 15:43:08 -0400 Subject: [PATCH] Calculate new actor addresses as per updated spec --- chain/vm/runtime.go | 12 ++++++++---- chain/vm/vm.go | 16 ++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index e6b450c8d..492900990 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -44,8 +44,7 @@ type Runtime struct { originNonce uint64 internalExecutions []*ExecutionResult - // the first internal call has a value of 1 for this field - internalCallCounter int64 + numActorsCreated uint64 } func (rs *Runtime) ResolveAddress(address address.Address) (ret address.Address, ok bool) { @@ -166,7 +165,7 @@ func (rt *Runtime) NewActorAddress() address.Address { if err := binary.Write(&b, binary.BigEndian, rt.originNonce); err != nil { rt.Abortf(exitcode.ErrSerialization, "writing nonce address into a buffer: %v", err) } - if err := binary.Write(&b, binary.BigEndian, rt.internalCallCounter); err != nil { // TODO: expose on vm + if err := binary.Write(&b, binary.BigEndian, rt.numActorsCreated); err != nil { // TODO: expose on vm rt.Abortf(exitcode.ErrSerialization, "writing callSeqNum address into a buffer: %v", err) } addr, err := address.NewActorAddress(b.Bytes()) @@ -174,6 +173,7 @@ func (rt *Runtime) NewActorAddress() address.Address { rt.Abortf(exitcode.ErrSerialization, "create actor address: %v", err) } + rt.incrementNumActorsCreated() return addr } @@ -340,7 +340,7 @@ func (rt *Runtime) internalSend(to address.Address, method abi.MethodNum, value if subrt != nil { er.Subcalls = subrt.internalExecutions - rt.internalCallCounter = subrt.internalCallCounter + rt.numActorsCreated = subrt.numActorsCreated } rt.internalExecutions = append(rt.internalExecutions, &er) return ret, errSend @@ -438,3 +438,7 @@ func (rt *Runtime) chargeGasSafe(toUse int64) aerrors.ActorError { func (rt *Runtime) Pricelist() Pricelist { return rt.pricelist } + +func (rt *Runtime) incrementNumActorsCreated() { + rt.numActorsCreated++ +} diff --git a/chain/vm/vm.go b/chain/vm/vm.go index cb337aaa8..15119b64c 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -115,7 +115,7 @@ func (bs *gasChargingBlocks) Put(blk block.Block) error { return nil } -func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin address.Address, originNonce uint64, usedGas int64, icc int64) *Runtime { +func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin address.Address, originNonce uint64, usedGas int64, nac uint64) *Runtime { rt := &Runtime{ ctx: ctx, vm: vm, @@ -125,10 +125,10 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin addres originNonce: originNonce, height: vm.blockHeight, - gasUsed: usedGas, - gasAvailable: msg.GasLimit, - internalCallCounter: icc, - pricelist: PricelistByEpoch(vm.blockHeight), + gasUsed: usedGas, + gasAvailable: msg.GasLimit, + numActorsCreated: nac, + pricelist: PricelistByEpoch(vm.blockHeight), } rt.cst = &cbor.BasicIpldStore{ Blocks: &gasChargingBlocks{rt.ChargeGas, rt.pricelist, vm.cst.Blocks}, @@ -216,14 +216,14 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime, origin := msg.From on := msg.Nonce - var icc int64 = 0 + var nac uint64 = 0 if parent != nil { gasUsed = parent.gasUsed + gasUsed origin = parent.origin on = parent.originNonce - icc = parent.internalCallCounter + 1 + nac = parent.numActorsCreated } - rt := vm.makeRuntime(ctx, msg, origin, on, gasUsed, icc) + rt := vm.makeRuntime(ctx, msg, origin, on, gasUsed, nac) if parent != nil { defer func() { parent.gasUsed = rt.gasUsed