Skip to content

Commit

Permalink
fix: state: rename Actor.Address and only use it for f4 addresses
Browse files Browse the repository at this point in the history
Per the FIP [1], the top-level actor address field should only be used
for delegated addresses. Unfortunately, the FIP's design was changed [2]
but neither lotus genesis code nor the field name were updated to
reflect this. Fortunately, all the migration code (on mainnet, at
least), has correctly left this field unset/unchanged (except for actors
with f4 addresses).

[1]: https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0048.md#new-lookup_delegated_address-syscall-and-state-changes
[2]: https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0048.md#recording-other-addresses-in-the-actorstate-root
  • Loading branch information
Stebalien committed Jun 27, 2024
1 parent 653210b commit f72ae9c
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 116 deletions.
56 changes: 28 additions & 28 deletions build/openrpc/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -15501,7 +15501,7 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
},
"GasCharges": [
Expand Down Expand Up @@ -15541,7 +15541,7 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
},
"GasCharges": [
Expand Down Expand Up @@ -15611,10 +15611,6 @@
"State": {
"additionalProperties": false,
"properties": {
"Address": {
"additionalProperties": false,
"type": "object"
},
"Balance": {
"additionalProperties": false,
"type": "object"
Expand All @@ -15623,6 +15619,10 @@
"title": "Content Identifier",
"type": "string"
},
"DelegatedAddress": {
"additionalProperties": false,
"type": "object"
},
"Head": {
"title": "Content Identifier",
"type": "string"
Expand Down Expand Up @@ -15892,18 +15892,14 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
}
],
"patternProperties": {
".*": {
"additionalProperties": false,
"properties": {
"Address": {
"additionalProperties": false,
"type": "object"
},
"Balance": {
"additionalProperties": false,
"type": "object"
Expand All @@ -15912,6 +15908,10 @@
"title": "Content Identifier",
"type": "string"
},
"DelegatedAddress": {
"additionalProperties": false,
"type": "object"
},
"Head": {
"title": "Content Identifier",
"type": "string"
Expand Down Expand Up @@ -16196,7 +16196,7 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
},
"GasCharges": [
Expand Down Expand Up @@ -16236,7 +16236,7 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
},
"GasCharges": [
Expand Down Expand Up @@ -16316,10 +16316,6 @@
"State": {
"additionalProperties": false,
"properties": {
"Address": {
"additionalProperties": false,
"type": "object"
},
"Balance": {
"additionalProperties": false,
"type": "object"
Expand All @@ -16328,6 +16324,10 @@
"title": "Content Identifier",
"type": "string"
},
"DelegatedAddress": {
"additionalProperties": false,
"type": "object"
},
"Head": {
"title": "Content Identifier",
"type": "string"
Expand Down Expand Up @@ -17001,15 +17001,11 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
],
"additionalProperties": false,
"properties": {
"Address": {
"additionalProperties": false,
"type": "object"
},
"Balance": {
"additionalProperties": false,
"type": "object"
Expand All @@ -17018,6 +17014,10 @@
"title": "Content Identifier",
"type": "string"
},
"DelegatedAddress": {
"additionalProperties": false,
"type": "object"
},
"Head": {
"title": "Content Identifier",
"type": "string"
Expand Down Expand Up @@ -21372,7 +21372,7 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
},
"GasCharges": [
Expand Down Expand Up @@ -21412,7 +21412,7 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
},
"GasCharges": [
Expand Down Expand Up @@ -21482,10 +21482,6 @@
"State": {
"additionalProperties": false,
"properties": {
"Address": {
"additionalProperties": false,
"type": "object"
},
"Balance": {
"additionalProperties": false,
"type": "object"
Expand All @@ -21494,6 +21490,10 @@
"title": "Content Identifier",
"type": "string"
},
"DelegatedAddress": {
"additionalProperties": false,
"type": "object"
},
"Head": {
"title": "Content Identifier",
"type": "string"
Expand Down
34 changes: 17 additions & 17 deletions build/openrpc/gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -6830,7 +6830,7 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
},
"GasCharges": [
Expand Down Expand Up @@ -6870,7 +6870,7 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
},
"GasCharges": [
Expand Down Expand Up @@ -6940,10 +6940,6 @@
"State": {
"additionalProperties": false,
"properties": {
"Address": {
"additionalProperties": false,
"type": "object"
},
"Balance": {
"additionalProperties": false,
"type": "object"
Expand All @@ -6952,6 +6948,10 @@
"title": "Content Identifier",
"type": "string"
},
"DelegatedAddress": {
"additionalProperties": false,
"type": "object"
},
"Head": {
"title": "Content Identifier",
"type": "string"
Expand Down Expand Up @@ -7418,15 +7418,11 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
],
"additionalProperties": false,
"properties": {
"Address": {
"additionalProperties": false,
"type": "object"
},
"Balance": {
"additionalProperties": false,
"type": "object"
Expand All @@ -7435,6 +7431,10 @@
"title": "Content Identifier",
"type": "string"
},
"DelegatedAddress": {
"additionalProperties": false,
"type": "object"
},
"Head": {
"title": "Content Identifier",
"type": "string"
Expand Down Expand Up @@ -9316,7 +9316,7 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
},
"GasCharges": [
Expand Down Expand Up @@ -9356,7 +9356,7 @@
},
"Nonce": 42,
"Balance": "0",
"Address": "f01234"
"DelegatedAddress": "f01234"
}
},
"GasCharges": [
Expand Down Expand Up @@ -9426,10 +9426,6 @@
"State": {
"additionalProperties": false,
"properties": {
"Address": {
"additionalProperties": false,
"type": "object"
},
"Balance": {
"additionalProperties": false,
"type": "object"
Expand All @@ -9438,6 +9434,10 @@
"title": "Content Identifier",
"type": "string"
},
"DelegatedAddress": {
"additionalProperties": false,
"type": "object"
},
"Head": {
"title": "Content Identifier",
"type": "string"
Expand Down
4 changes: 2 additions & 2 deletions chain/consensus/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ func IsValidForSending(nv network.Version, act *types.Actor) bool {

// Allow placeholder actors with a delegated address and nonce 0 to send a message.
// These will be converted to an EthAccount actor on first send.
if !builtin.IsPlaceholderActor(act.Code) || act.Nonce != 0 || act.Address == nil || act.Address.Protocol() != address.Delegated {
if !builtin.IsPlaceholderActor(act.Code) || act.Nonce != 0 || act.DelegatedAddress == nil || act.DelegatedAddress.Protocol() != address.Delegated {
return false
}

// Only allow such actors to send if their delegated address is in the EAM's namespace.
id, _, err := varint.FromUvarint(act.Address.Payload())
id, _, err := varint.FromUvarint(act.DelegatedAddress.Payload())
return err == nil && id == builtintypes.EthereumAddressManagerActorID
}

Expand Down
28 changes: 14 additions & 14 deletions chain/consensus/filcns/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2115,11 +2115,11 @@ func buildUpgradeActorsV12MinerFix(oldBuggyMinerCID, newManifestCID cid.Cid) fun
}

return actorsOut.SetActor(a, &types.ActorV5{
Code: newCid,
Head: actor.Head,
Nonce: actor.Nonce,
Balance: actor.Balance,
Address: actor.Address,
Code: newCid,
Head: actor.Head,
Nonce: actor.Nonce,
Balance: actor.Balance,
DelegatedAddress: actor.DelegatedAddress,
})
})
if err != nil {
Expand Down Expand Up @@ -2153,8 +2153,8 @@ func buildUpgradeActorsV12MinerFix(oldBuggyMinerCID, newManifestCID cid.Cid) fun
return xerrors.Errorf("mismatched balance for actor %s: %d != %d", a, inActor.Balance, outActor.Balance)
}

if inActor.Address != outActor.Address && inActor.Address.String() != outActor.Address.String() {
return xerrors.Errorf("mismatched address for actor %s: %s != %s", a, inActor.Address, outActor.Address)
if inActor.DelegatedAddress != outActor.DelegatedAddress && inActor.DelegatedAddress.String() != outActor.DelegatedAddress.String() {
return xerrors.Errorf("mismatched address for actor %s: %s != %s", a, inActor.DelegatedAddress, outActor.DelegatedAddress)
}

if inActor.Head != outActor.Head && a != builtin.SystemActorAddr {
Expand Down Expand Up @@ -2413,11 +2413,11 @@ func upgradeActorsV13VerifregFix(oldBuggyVerifregCID, newManifestCID cid.Cid) fu
}

return actorsOut.SetActor(a, &types.ActorV5{
Code: newCid,
Head: actor.Head,
Nonce: actor.Nonce,
Balance: actor.Balance,
Address: actor.Address,
Code: newCid,
Head: actor.Head,
Nonce: actor.Nonce,
Balance: actor.Balance,
DelegatedAddress: actor.DelegatedAddress,
})
})
if err != nil {
Expand Down Expand Up @@ -2451,8 +2451,8 @@ func upgradeActorsV13VerifregFix(oldBuggyVerifregCID, newManifestCID cid.Cid) fu
return xerrors.Errorf("mismatched balance for actor %s: %d != %d", a, inActor.Balance, outActor.Balance)
}

if inActor.Address != outActor.Address && inActor.Address.String() != outActor.Address.String() {
return xerrors.Errorf("mismatched address for actor %s: %s != %s", a, inActor.Address, outActor.Address)
if inActor.DelegatedAddress != outActor.DelegatedAddress && inActor.DelegatedAddress.String() != outActor.DelegatedAddress.String() {
return xerrors.Errorf("mismatched address for actor %s: %s != %s", a, inActor.DelegatedAddress, outActor.DelegatedAddress)
}

if inActor.Head != outActor.Head && a != builtin.SystemActorAddr {
Expand Down
13 changes: 9 additions & 4 deletions chain/gen/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,16 @@ func MakeAccountActor(ctx context.Context, cst cbor.IpldStore, av actorstypes.Ve
return nil, xerrors.Errorf("failed to get account actor code ID for actors version %d", av)
}

var delegatedAddr *address.Address
if addr.Protocol() == address.Delegated {
delegatedAddr = &addr
}

act := &types.Actor{
Code: actcid,
Head: statecid,
Balance: bal,
Address: &addr,
Code: actcid,
Head: statecid,
Balance: bal,
DelegatedAddress: delegatedAddr,
}

return act, nil
Expand Down
Loading

0 comments on commit f72ae9c

Please sign in to comment.