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

feat: add support for creating allocations via EVM contract #1970

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

kacperzuk-neti
Copy link
Contributor

See #1961 for detailed context.

Summary

This PR adds a new option to boost allocate command: --evm-client-contract. When the option is provided, instead of calling transfer method on datacap actor directly, it invokes transfer method on the provided EVM contract. It's assumed that the contract is an instance of fidlabs Client.sol.

Notable changes

As recommended by @LexLuthr , this adds go-ethereum dependency. This requires replacing go-crypto v0.0.1 with v0.1.0 to make linker happy.

Tests

No unit tests were added, as new code relies heavily on API. No integration tests were added, as the feature depends on an external smart contract. If you think unit or integration tests should be added, please provide guidance on how to make this work.

It tested manually using the docker devnet with the following procedure:

  1. Start devnet
  2. Deployed an instance of Client.sol to devnet, granted Datacap to it
  3. Run boost allocate with --evm-client-contract option and verified that it failed
  4. Called 'increaseAllowance(address,uint256)' on the Client.sol contract to grant datacap allowance to boost address
  5. Run boost allocate again, verified that it succeeded
  6. Run lotus filplus list-allocations to verify that allocation was created

Let me know if detailed instruction for setting up a dev env with the contract is needed.

Known Issues

For me, on docker devnet, it sometimes fails with 03: f06 (method 3726118371) -- allocation expiration 195886 exceeds maximum 195885 (16). The expiration is always 1 higher than the maximum. This is unrelated to the contract change, as this is something I also experience on main branch version with normal allocations.

Copy link
Collaborator

@LexLuthr LexLuthr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good with some changes required. Can we please paste invoked command and the test results in the PR? It would also be ideal to test batch request transfer as well. Please test it on the limit of 500.

@@ -93,6 +93,10 @@ var directDealAllocate = &cli.Command{
Usage: "automatic yes to prompts; assume 'yes' as answer to all prompts and run non-interactively",
Aliases: []string{"y", "yes"},
},
&cli.StringFlag{
Name: "evm-client-contract",
Usage: "address of EVM contract to spend DataCap from",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should clarify here that we are expecting F4 address and not Eth address.

return err
var msgs []*types.Message
var allocationsAddr address.Address
evmContract := cctx.String("evm-client-contract")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest checking if the flag is set and if the value if empty then return an error.

@@ -287,7 +307,7 @@ var directDealAllocate = &cli.Command{
mcidStr = append(mcidStr, c.String())
}

log.Infow("submitted data cap allocation message[s]", mcidStr)
log.Infow("submitted data cap allocation message[s]", "mcidStr", mcidStr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Infow("submitted data cap allocation message[s]", "mcidStr", mcidStr)
log.Infow("submitted data cap allocation message[s]", "CID", mcidStr)

}

// Decode return value (cbor -> evm ABI -> math/big Int -> filecoin big Int)
var decodedReturn abi.CborBytes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check exit code success here before unmarshaling the result

@LexLuthr
Copy link
Collaborator

LexLuthr commented Oct 3, 2024

Please fix the failing test as well

@kacperzuk-neti
Copy link
Contributor Author

Code updated as requested in review and bench test is fixed.

Manual test results & invoke commands:

  1. Correctly detects lack of datacap on contract:

    > ./boost allocate --evm-client-contract=t410fh5yvieuehp5wc325elm6odrswnkopxobxafolsy --miner=t01000 --piece-info=baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq=8388608 --wallet f3uatcjl57mrk6qxdpd3f3nmpr5n66khcrelkzpgts3zoilfn6sjt3fv5nn5kkjyk5pkrjdi3mfshmzkbg5bta
    Error: contract f3uatcjl57mrk6qxdpd3f3nmpr5n66khcrelkzpgts3zoilfn6sjt3fv5nn5kkjyk5pkrjdi3mfshmzkbg5bta does not have any datacap
    
  2. Correctly detects lack of allowance on contract:

    > docker exec -it lotus lotus filplus grant-datacap --from t01005 t410fh5yvieuehp5wc325elm6odrswnkopxobxafolsy 5000000000
    message sent, now waiting on cid: bafy2bzacecgshzguh5jmx3n3xqt3biwjcjefeaa3n75l5cfejx23svneajgqq
    > ./boost allocate --evm-client-contract=t410fh5yvieuehp5wc325elm6odrswnkopxobxafolsy --miner=t01000 --piece-info=baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq=8388608 --wallet f3uatcjl57mrk6qxdpd3f3nmpr5n66khcrelkzpgts3zoilfn6sjt3fv5nn5kkjyk5pkrjdi3mfshmzkbg5bta
    Error: requested datacap 8388608 is greater then the available datacap allowance 0
    
  3. Correctly creates allocation in the simplest case:

    > cast send --rpc-url localhost:1234/rpc/v1 --private-key 47751c9fb99b6f538691db2facce453c1036b5b6ccfef4f1bc6a8fc55cf583a2 0x3f715412843bfb616f5d22d9e70e32b354e7ddc1 'increaseAllowance(address,uint256)' 0xff000000000000000000000000000000000003ef 99999999999999999999999999
    [...]
    status                  1 (success)
    [...]
    
    > ./boost allocate --evm-client-contract=t410fh5yvieuehp5wc325elm6odrswnkopxobxafolsy --miner=t01000 --piece-info=baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq=8388608 --wallet f3uatcjl57mrk6qxdpd3f3nmpr5n66khcrelkzpgts3zoilfn6sjt3fv5nn5kkjyk5pkrjdi3mfshmzkbg5bta
    about to send message with the following gas costs
    max fee:      0.000000095762846696 FIL (absolute maximum amount you are willing to pay to get your transaction confirmed)
    gas fee cap:  0.000000000000001861 FIL
    gas limit:    51457736
    gas premium:  0.000000000000000019 FIL
    basefee:      0.000000000000001551 FIL
    nonce:        0
    
    Proceed? Yes [Y/y] / No [N/n], Ctrl+C (^C) to exit y
    sent message:  bafy2bzaceds6t7aejdx6ykakq7kyvuc3pzl3m56cjqsevk4c27pjnx3uyzbjs
    2024-10-03T12:14:43.374+0200    INFO    boost   boost/direct_deal.go:313        submitted data cap allocation message[s]        {"CID": ["bafy2bzaceds6t7aejdx6ykakq7kyvuc3pzl3m56cjqsevk4c27pjnx3uyzbjs"]}
    2024-10-03T12:14:43.375+0200    INFO    boost   boost/direct_deal.go:314        waiting for message to be included in a block
    AllocationID  Client  Miner  PieceCid                                                          PieceSize  TermMin  TermMax  
    2             1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 172884
      
    > docker exec -it lotus lotus filplus list-allocations
    AllocationID  Client  Miner  PieceCid                                                          PieceSize  TermMin  TermMax  Expiration  
    2             1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  172884  
    
  4. Batch of 5 allocations in single transaction:

        > rm -f piece-infos.csv; for i in $(seq 5); do echo 'baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq,8388608,t01000,518400,5256000,1000' >> piece-infos.csv; done
    > $ ./boost allocate --batch-size 5 --piece-file=piece-infos.csv --evm-client-contract=t410fh5yvieuehp5wc325elm6odrswnkopxobxafolsy --miner=t01000 --wallet f3uatcjl57mrk6qxdpd3f3nmpr5n66khcrelkzpgts3zoilfn6sjt3fv5nn5kkjyk5pkrjdi3mfshmzkbg5bta
    about to send message with the following gas costs
    max fee:      0.00000000933962712 FIL (absolute maximum amount you are willing to pay to get your transaction confirmed)
    gas fee cap:  0.00000000000000012 FIL
    gas limit:    77830226
    gas premium:  0.000000000000000012 FIL
    basefee:      0.0000000000000001 FIL
    nonce:        1
    
    Proceed? Yes [Y/y] / No [N/n], Ctrl+C (^C) to exit y
    sent message:  bafy2bzaceartanjhs2cgrrddmkjylcxkn7ihjulmmtcwa73hibyuorgb3zsxw
    2024-10-03T12:16:10.965+0200    INFO    boost   boost/direct_deal.go:313        submitted data cap allocation message[s]        {"CID": ["bafy2bzaceartanjhs2cgrrddmkjylcxkn7ihjulmmtcwa73hibyuorgb3zsxw"]}
    2024-10-03T12:16:10.965+0200    INFO    boost   boost/direct_deal.go:314        waiting for message to be included in a block
    AllocationID  Client  Miner  PieceCid                                                          PieceSize  TermMin  TermMax  
    7             1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1106
    3             1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1106
    4             1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1106
    5             1011    1000   baga6ea5seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1106
    6             1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1106
    
  5. Batch of 500 in a single transaction:

    > rm -f piece-infos.csv; for i in $(seq 500); do echo 'baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq,8388608,t01000,518400,5256000,1000' >> piece-infos.csv; done
    > ./boost allocate --batch-size 500 --piece-file=piece-infos.csv --evm-client-contract=t410fh5yvieuehp5wc325elm6odrswnkopxobxafolsy --miner=t01000 --wallet f3uatcjl57mrk6qxdpd3f3nmpr5n66khcrelkzpgts3zoilfn6sjt3fv5nn5kkjyk5pkrjdi3mfshmzkbg5bta
    about to send message with the following gas costs
    max fee:      0.00000041377482912 FIL (absolute maximum amount you are willing to pay to get your transaction confirmed)
    gas fee cap:  0.00000000000000012 FIL
    gas limit:    3448123576
    gas premium:  0 FIL
    basefee:      0.0000000000000001 FIL
    nonce:        2
    
    Proceed? Yes [Y/y] / No [N/n], Ctrl+C (^C) to exit y
    sent message:  bafy2bzaceccw4glfhy54cvx44klnkyf7ojsppfoowrpwh45ifhjylguo2fq3u
    2024-10-03T12:17:13.600+0200    INFO    boost   boost/direct_deal.go:313        submitted data cap allocation message[s]        {"CID": ["bafy2bzaceccw4glfhy54cvx44klnkyf7ojsppfoowrpwh45ifhjylguo2fq3u"]}
    2024-10-03T12:17:13.600+0200    INFO    boost   boost/direct_deal.go:314        waiting for message to be included in a block
    AllocationID  Client  Miner  PieceCid                                                          PieceSize  TermMin  TermMax  
    60            1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    75            1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    230           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    405           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    299           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    316           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    433           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    177           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    203           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    409           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    126           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    341           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    287           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1122
    [...]
    
  6. 500 allocations in batches of 200:

    > ./boost allocate --batch-size 200 --piece-file=piece-infos.csv --evm-client-contract=t410fh5yvieuehp5wc325elm6odrswnkopxobxafolsy --miner=t01000 --wallet f3uatcjl57mrk6qxdpd3f3nmpr5n66khcrelkzpgts3zoilfn6sjt3fv5nn5kkjyk5pkrjdi3mfshmzkbg5bta
    about to send message with the following gas costs
    max fee:      0.000000196842759 FIL (absolute maximum amount you are willing to pay to get your transaction confirmed)
    gas fee cap:  0.00000000000000012 FIL
    gas limit:    1640356325
    gas premium:  0 FIL
    basefee:      0.0000000000000001 FIL
    nonce:        3
    
    Proceed? Yes [Y/y] / No [N/n], Ctrl+C (^C) to exit y
    sent message:  bafy2bzacebuv73t6gv6gb55whafcw7n432lt3kt52u4srthzljhcq4l73cqru
    about to send message with the following gas costs
    max fee:      0.00000020614480896 FIL (absolute maximum amount you are willing to pay to get your transaction confirmed)
    gas fee cap:  0.00000000000000012 FIL
    gas limit:    1717873408
    gas premium:  0 FIL
    basefee:      0.0000000000000001 FIL
    nonce:        4
    
    Proceed? Yes [Y/y] / No [N/n], Ctrl+C (^C) to exit y
    sent message:  bafy2bzacecwdntakwztmq7lnslypwi5qtjul5eo7zbtz2rbswcqezkvh7vwda
    about to send message with the following gas costs
    max fee:      0.00000012713347392 FIL (absolute maximum amount you are willing to pay to get your transaction confirmed)
    gas fee cap:  0.00000000000000012 FIL
    gas limit:    1059445616
    gas premium:  0 FIL
    basefee:      0.0000000000000001 FIL
    nonce:        5
    
    Proceed? Yes [Y/y] / No [N/n], Ctrl+C (^C) to exit y
    sent message:  bafy2bzacecqaq3rzypkp7u7f4jajthwpwzd2ntnqc2vqc3d3b7e7akoc3pa4w
    2024-10-03T12:19:06.925+0200    INFO    boost   boost/direct_deal.go:313        submitted data cap allocation message[s]        {"CID": ["bafy2bzacebuv73t6gv6gb55whafcw7n432lt3kt52u4srthzljhcq4l73cqru", "bafy2bzacecwdntakwztmq7lnslypwi5qtjul5eo7zbtz2rbswcqezkvh7vwda", "bafy2bzacecqaq3rzypkp7u7f4jajthwpwzd2ntnqc2vqc3d3b7e7akoc3pa4w"]}
    2024-10-03T12:19:06.925+0200    INFO    boost   boost/direct_deal.go:314        waiting for message to be included in a block
    AllocationID  Client  Miner  PieceCid                                                          PieceSize  TermMin  TermMax  
    864           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1149
    886           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1149
    557           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1149
    798           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1149
    951           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1149
    731           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1149
    736           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1149
    674           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1149
    892           1011    1000   baga6ea4seaqedj5brnac3tlfmmzxfvt62dddaqnpif6qnjztzhznrhpzmk6gcgq  8388608    518400   5256000  
      Expiration: 1149
    [...]
    
  7. Verify final count of allocations (1 + 5 + 500 + 500 + header line = 1007):

    > docker exec -it lotus lotus filplus list-allocations | wc -l
    1007
    

Copy link
Collaborator

@LexLuthr LexLuthr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@LexLuthr LexLuthr merged commit 620a97f into filecoin-project:main Oct 3, 2024
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants