Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate new actor addresses as per updated spec #1429

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions chain/vm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -166,14 +165,15 @@ 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())
if err != nil {
rt.Abortf(exitcode.ErrSerialization, "create actor address: %v", err)
}

rt.incrementNumActorsCreated()
return addr
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++
}
16 changes: 8 additions & 8 deletions chain/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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},
Expand Down Expand Up @@ -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
Expand Down