Skip to content

Commit

Permalink
Merge pull request #5598 from filecoin-project/chore/account-abstraction
Browse files Browse the repository at this point in the history
chore: account abstraction
  • Loading branch information
diwufeiwen authored Dec 20, 2022
2 parents 5b0ebd3 + caa7116 commit 7a129b9
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 60 deletions.
8 changes: 4 additions & 4 deletions pkg/consensus/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,13 @@ func (bv *BlockValidator) VerifyWinningPoStProof(ctx context.Context, nv network
return nil
}

func isValidForSending(act *types.Actor) bool {
if builtin.IsAccountActor(act.Code) {
func IsValidForSending(act *types.Actor) bool {
if builtin.IsAccountActor(act.Code) || builtin.IsEthAccountActor(act.Code) {
return true
}

// HACK: Allow Eth embryos to send messages
if !builtin.IsEmbryo(act.Code) || act.Address == nil || act.Address.Protocol() != address.Delegated {
if !builtin.IsEmbryoActor(act.Code) || act.Address == nil || act.Address.Protocol() != address.Delegated {
return false
}
id, _, err := varint.FromUvarint(act.Address.Payload())
Expand Down Expand Up @@ -830,7 +830,7 @@ func (bv *BlockValidator) checkBlockMessages(ctx context.Context, sigValidator *
return fmt.Errorf("actor %s not found", sender)
}

if isValidForSending(act) {
if IsValidForSending(act) {
return errors.New("sender must be an account actor")
}
nonces[sender] = act.Nonce
Expand Down
19 changes: 15 additions & 4 deletions pkg/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/filecoin-project/venus/pkg/chain"
"github.com/filecoin-project/venus/pkg/config"
"github.com/filecoin-project/venus/pkg/consensus"
"github.com/filecoin-project/venus/pkg/constants"
crypto2 "github.com/filecoin-project/venus/pkg/crypto"
"github.com/filecoin-project/venus/pkg/messagepool/journal"
Expand Down Expand Up @@ -841,7 +842,7 @@ func sigCacheKey(m *types.SignedMessage) (string, error) {
case crypto.SigTypeDelegated:
txArgs, err := types.NewEthTxArgsFromMessage(&m.Message)
if err != nil {
return "", err
return "", fmt.Errorf("failed to convert to eth tx args: %w", err)
}
msg, err := txArgs.HashedOriginalRlpMsg()
if err != nil {
Expand Down Expand Up @@ -921,18 +922,28 @@ func (mp *MessagePool) addTS(ctx context.Context, m *types.SignedMessage, curTS
mp.lk.Lock()
defer mp.lk.Unlock()

senderAct, err := mp.api.GetActorAfter(ctx, m.Message.From, curTS)
if err != nil {
return false, fmt.Errorf("failed to get sender actor: %w", err)
}

// TODO: I'm not thrilled about depending on filcns here, but I prefer this to duplicating logic
if !consensus.IsValidForSending(senderAct) {
return false, fmt.Errorf("sender actor %s is not a valid top-level sender", m.Message.From)
}

publish, err := mp.verifyMsgBeforeAdd(ctx, m, curTS, local)
if err != nil {
return false, err
return false, fmt.Errorf("verify msg failed: %w", err)
}

if err := mp.checkBalance(ctx, m, curTS); err != nil {
return false, err
return false, fmt.Errorf("failed to check balance: %w", err)
}

err = mp.addLocked(ctx, m, !local, untrusted)
if err != nil {
return false, err
return false, fmt.Errorf("failed to add locked: %w", err)
}

if local {
Expand Down
2 changes: 1 addition & 1 deletion pkg/messagepool/messagepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (tma *testMpoolAPI) GetActorAfter(ctx context.Context, addr address.Address
}

return &types.Actor{
Code: builtin2.StorageMarketActorCodeID,
Code: builtin2.AccountActorCodeID,
Nonce: nonce,
Balance: balance,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/vm/register/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetDefaultActros() *dispatch.CodeLoader {
}

func DumpActorState(codeLoader *dispatch.CodeLoader, act *types.Actor, b []byte) (interface{}, error) {
if builtin.IsAccountActor(act.Code) || builtin.IsEmbryo(act.Code) { // Account code special case
if builtin.IsAccountActor(act.Code) || builtin.IsEmbryoActor(act.Code) { // Account code special case
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion venus-devtool/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/filecoin-project/go-fil-markets v1.25.2
github.com/filecoin-project/go-jsonrpc v0.1.9
github.com/filecoin-project/go-state-types v0.10.0-alpha-5
github.com/filecoin-project/lotus v1.18.2-0.20221215215610-d574eda147ed
github.com/filecoin-project/lotus v1.18.2-0.20221216222459-5f4ccfd79084
github.com/filecoin-project/venus v0.0.0-00010101000000-000000000000
github.com/google/uuid v1.3.0
github.com/ipfs/go-block-format v0.0.3
Expand Down
4 changes: 2 additions & 2 deletions venus-devtool/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWc
github.com/filecoin-project/go-statestore v0.2.0 h1:cRRO0aPLrxKQCZ2UOQbzFGn4WDNdofHZoGPjfNaAo5Q=
github.com/filecoin-project/go-statestore v0.2.0/go.mod h1:8sjBYbS35HwPzct7iT4lIXjLlYyPor80aU7t7a/Kspo=
github.com/filecoin-project/index-provider v0.9.1 h1:Jnh9dviIHvQxZ2baNoYu3n8z6F9O62ksnVlyREgPyyM=
github.com/filecoin-project/lotus v1.18.2-0.20221215215610-d574eda147ed h1:NiMBCcyejzzcY4qvW/CK9dAlEN5p5qy9/j6573Gi9HI=
github.com/filecoin-project/lotus v1.18.2-0.20221215215610-d574eda147ed/go.mod h1:mYznBAFEEfBGY4c081A0UiyX0GxHn0F9528JJ0r5mVw=
github.com/filecoin-project/lotus v1.18.2-0.20221216222459-5f4ccfd79084 h1:hda9tgw3nIYezGT7PXs6EsiQAcwI4gJmyZ0BWk4A+hk=
github.com/filecoin-project/lotus v1.18.2-0.20221216222459-5f4ccfd79084/go.mod h1:t8BPmtBAmA3srP4xzxq8gH0DKiigloW20KKQwO2PZWk=
github.com/filecoin-project/pubsub v1.0.0 h1:ZTmT27U07e54qV1mMiQo4HDr0buo8I1LDHBYLXlsNXM=
github.com/filecoin-project/pubsub v1.0.0/go.mod h1:GkpB33CcUtUNrLPhJgfdy4FDx4OMNR9k+46DHx/Lqrg=
github.com/filecoin-project/specs-actors v0.9.13/go.mod h1:TS1AW/7LbG+615j4NsjMK1qlpAwaFsG9w0V2tg2gSao=
Expand Down
27 changes: 18 additions & 9 deletions venus-shared/actors/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ func ActorNameByCode(c cid.Cid) string {
}
}

func IsEmbryo(c cid.Cid) bool {
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == "embryo"
}

return false
}

func IsBuiltinActor(c cid.Cid) bool {
_, _, ok := actors.GetActorMetaByCode(c)
if ok {
Expand Down Expand Up @@ -293,6 +284,24 @@ func IsPaymentChannelActor(c cid.Cid) bool {
return false
}

func IsEmbryoActor(c cid.Cid) bool {
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == "embryo"
}

return false
}

func IsEthAccountActor(c cid.Cid) bool {
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == "ethaccount"
}

return false
}

func makeAddress(addr string) address.Address {
ret, err := address.NewFromString(addr)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions venus-shared/actors/builtin/builtin.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,24 @@ func IsPaymentChannelActor(c cid.Cid) bool {
return false
}

func IsEmbryoActor(c cid.Cid) bool {
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == "embryo"
}

return false
}

func IsEthAccountActor(c cid.Cid) bool {
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == "ethaccount"
}

return false
}

func makeAddress(addr string) address.Address {
ret, err := address.NewFromString(addr)
if err != nil {
Expand Down
33 changes: 22 additions & 11 deletions venus-shared/api/chain/v0/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ Response:
{
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
}
]
```
Expand Down Expand Up @@ -820,7 +821,8 @@ Response:
{
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
}
]
```
Expand Down Expand Up @@ -1257,7 +1259,8 @@ Response:
"Receipt": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
}
}
```
Expand Down Expand Up @@ -1395,7 +1398,8 @@ Response:
"MsgRct": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"GasCost": {
"Message": {
Expand Down Expand Up @@ -1428,7 +1432,8 @@ Response:
"MsgRct": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"Error": "string value",
"Duration": 60000000000,
Expand Down Expand Up @@ -1472,7 +1477,8 @@ Response:
"MsgRct": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"Error": "string value",
"Duration": 60000000000,
Expand Down Expand Up @@ -1576,7 +1582,8 @@ Response:
{
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
}
```

Expand Down Expand Up @@ -1633,7 +1640,8 @@ Response:
"Receipt": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"ReturnDec": {},
"TipSet": [
Expand Down Expand Up @@ -1672,7 +1680,8 @@ Response:
"Receipt": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"ReturnDec": {},
"TipSet": [
Expand Down Expand Up @@ -1754,7 +1763,8 @@ Response:
"Receipt": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"ReturnDec": {},
"TipSet": [
Expand Down Expand Up @@ -1794,7 +1804,8 @@ Response:
"Receipt": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"ReturnDec": {},
"TipSet": [
Expand Down
24 changes: 16 additions & 8 deletions venus-shared/api/chain/v1/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ Response:
{
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
}
]
```
Expand Down Expand Up @@ -786,7 +787,8 @@ Response:
{
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
}
]
```
Expand Down Expand Up @@ -1252,7 +1254,8 @@ Response:
"Receipt": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
}
}
```
Expand Down Expand Up @@ -1390,7 +1393,8 @@ Response:
"MsgRct": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"GasCost": {
"Message": {
Expand Down Expand Up @@ -1423,7 +1427,8 @@ Response:
"MsgRct": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"Error": "string value",
"Duration": 60000000000,
Expand Down Expand Up @@ -1467,7 +1472,8 @@ Response:
"MsgRct": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"Error": "string value",
"Duration": 60000000000,
Expand Down Expand Up @@ -1694,7 +1700,8 @@ Response:
"Receipt": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"ReturnDec": {},
"TipSet": [
Expand Down Expand Up @@ -1796,7 +1803,8 @@ Response:
"Receipt": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"ReturnDec": {},
"TipSet": [
Expand Down
3 changes: 2 additions & 1 deletion venus-shared/api/market/client/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,8 @@ Response:
"Receipt": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"ReturnDec": {},
"TipSet": [
Expand Down
3 changes: 2 additions & 1 deletion venus-shared/api/market/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,8 @@ Response:
"Receipt": {
"ExitCode": 0,
"Return": "Ynl0ZSBhcnJheQ==",
"GasUsed": 9
"GasUsed": 9,
"EventsRoot": null
},
"ReturnDec": {},
"TipSet": [
Expand Down
Loading

0 comments on commit 7a129b9

Please sign in to comment.