Skip to content

Commit

Permalink
add gas fee payer by adding a new payload type (#8904)
Browse files Browse the repository at this point in the history
* first update

* Use RawTransactionWithData

* fix all locations

* introduce the gas fee authenticator

* Push the gas fee payer transaction authenticator throughout the code
* Start poking at the use of the bit to indicate gas fee payer

* [fee-payer] plumb through the VM and framework

* move tests pass

* fix prover

* fix order

* regen

* Add

* restore sdk/src/types.rs

* remove old comment

---------

Co-authored-by: David Wolinsky <isaac.wolinsky@gmail.com>
  • Loading branch information
gerben-stavenga and davidiw authored Jul 4, 2023
1 parent 2d1ae23 commit 604cb4f
Show file tree
Hide file tree
Showing 45 changed files with 3,136 additions and 1,667 deletions.
75 changes: 74 additions & 1 deletion api/doc/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -12420,6 +12420,56 @@
}
}
},
"FeePayerSignature": {
"type": "object",
"description": "Fee payer signature for fee payer transactions\n\nThis allows you to have transactions across multiple accounts and with a fee payer",
"required": [
"sender",
"secondary_signer_addresses",
"secondary_signers",
"fee_payer_address",
"fee_payer_signer"
],
"properties": {
"sender": {
"$ref": "#/components/schemas/AccountSignature"
},
"secondary_signer_addresses": {
"type": "array",
"description": "The other involved parties' addresses",
"items": {
"$ref": "#/components/schemas/Address"
}
},
"secondary_signers": {
"type": "array",
"description": "The associated signatures, in the same order as the secondary addresses",
"items": {
"$ref": "#/components/schemas/AccountSignature"
}
},
"fee_payer_address": {
"allOf": [
{
"$ref": "#/components/schemas/Address"
},
{
"description": "The address of the paying party"
}
]
},
"fee_payer_signer": {
"allOf": [
{
"$ref": "#/components/schemas/AccountSignature"
},
{
"description": "The signature of the fee payer"
}
]
}
}
},
"GasEstimation": {
"type": "object",
"description": "Struct holding the outputs of the estimate gas API",
Expand Down Expand Up @@ -13394,14 +13444,18 @@
},
{
"$ref": "#/components/schemas/TransactionSignature_MultiAgentSignature"
},
{
"$ref": "#/components/schemas/TransactionSignature_FeePayerSignature"
}
],
"discriminator": {
"propertyName": "type",
"mapping": {
"ed25519_signature": "#/components/schemas/TransactionSignature_Ed25519Signature",
"multi_ed25519_signature": "#/components/schemas/TransactionSignature_MultiEd25519Signature",
"multi_agent_signature": "#/components/schemas/TransactionSignature_MultiAgentSignature"
"multi_agent_signature": "#/components/schemas/TransactionSignature_MultiAgentSignature",
"fee_payer_signature": "#/components/schemas/TransactionSignature_FeePayerSignature"
}
}
},
Expand All @@ -13424,6 +13478,25 @@
}
]
},
"TransactionSignature_FeePayerSignature": {
"allOf": [
{
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"example": "fee_payer_signature"
}
}
},
{
"$ref": "#/components/schemas/FeePayerSignature"
}
]
},
"TransactionSignature_MultiAgentSignature": {
"allOf": [
{
Expand Down
46 changes: 46 additions & 0 deletions api/doc/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9316,6 +9316,40 @@ components:
$ref: '#/components/schemas/U64'
account_address:
$ref: '#/components/schemas/Address'
FeePayerSignature:
type: object
description: |-
Fee payer signature for fee payer transactions
This allows you to have transactions across multiple accounts and with a fee payer
required:
- sender
- secondary_signer_addresses
- secondary_signers
- fee_payer_address
- fee_payer_signer
properties:
sender:
$ref: '#/components/schemas/AccountSignature'
secondary_signer_addresses:
type: array
description: The other involved parties' addresses
items:
$ref: '#/components/schemas/Address'
secondary_signers:
type: array
description: The associated signatures, in the same order as the secondary
addresses
items:
$ref: '#/components/schemas/AccountSignature'
fee_payer_address:
allOf:
- $ref: '#/components/schemas/Address'
- description: The address of the paying party
fee_payer_signer:
allOf:
- $ref: '#/components/schemas/AccountSignature'
- description: The signature of the fee payer
GasEstimation:
type: object
description: Struct holding the outputs of the estimate gas API
Expand Down Expand Up @@ -10088,12 +10122,14 @@ components:
- $ref: '#/components/schemas/TransactionSignature_Ed25519Signature'
- $ref: '#/components/schemas/TransactionSignature_MultiEd25519Signature'
- $ref: '#/components/schemas/TransactionSignature_MultiAgentSignature'
- $ref: '#/components/schemas/TransactionSignature_FeePayerSignature'
discriminator:
propertyName: type
mapping:
ed25519_signature: '#/components/schemas/TransactionSignature_Ed25519Signature'
multi_ed25519_signature: '#/components/schemas/TransactionSignature_MultiEd25519Signature'
multi_agent_signature: '#/components/schemas/TransactionSignature_MultiAgentSignature'
fee_payer_signature: '#/components/schemas/TransactionSignature_FeePayerSignature'
TransactionSignature_Ed25519Signature:
allOf:
- type: object
Expand All @@ -10104,6 +10140,16 @@ components:
type: string
example: ed25519_signature
- $ref: '#/components/schemas/Ed25519Signature'
TransactionSignature_FeePayerSignature:
allOf:
- type: object
required:
- type
properties:
type:
type: string
example: fee_payer_signature
- $ref: '#/components/schemas/FeePayerSignature'
TransactionSignature_MultiAgentSignature:
allOf:
- type: object
Expand Down
67 changes: 67 additions & 0 deletions api/src/tests/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,74 @@ async fn test_multi_agent_signed_transaction() {
.post("/transactions", resp)
.await;
}
/* works when feature is enabled
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_fee_payer_signed_transaction() {
let mut context = new_test_context(current_function_name!());
let account = context.gen_account();
let secondary = context.gen_account();
let factory = context.transaction_factory();
let mut root_account = context.root_account().await;
// Create secondary signer account
context
.commit_block(&[context.create_user_account_by(&mut root_account, &secondary)])
.await;
// Create a new account with a multi-agent signer
let txn = root_account.sign_fee_payer_with_transaction_builder(
vec![], &secondary,
factory.create_user_account(account.public_key()),
);
let body = bcs::to_bytes(&txn).unwrap();
let resp = context
.expect_status_code(202)
.post_bcs_txn("/transactions", body)
.await;
let (sender, secondary_signers,fee_payer_signer) = match txn.authenticator() {
TransactionAuthenticator::FeePayer {
sender,
secondary_signer_addresses: _,
secondary_signers,
fee_payer_address: _,
fee_payer_signer
} => (sender, secondary_signers, fee_payer_signer),
_ => panic!(
"expecting TransactionAuthenticator::MultiAgent, but got: {:?}",
txn.authenticator()
),
};
assert_json(
resp["signature"].clone(),
json!({
"type": "fee_payer_signature",
"sender": {
"type": "ed25519_signature",
"public_key": format!("0x{}", hex::encode(sender.public_key_bytes())),
"signature": format!("0x{}", hex::encode(sender.signature_bytes())),
},
"secondary_signer_addresses": [
],
"secondary_signers": [
],
"fee_payer_address": secondary.address().to_hex_literal(),
"fee_payer_signer": {
"type": "ed25519_signature",
"public_key": format!("0x{}",hex::encode(fee_payer_signer.public_key_bytes())),
"signature": format!("0x{}", hex::encode(fee_payer_signer.signature_bytes())),
},
}),
);
// ensure fee payer txns can be submitted into mempool by JSON format
context
.expect_status_code(202)
.post("/transactions", resp)
.await;
}
*/
#[ignore]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_multi_ed25519_signed_transaction() {
Expand Down
16 changes: 8 additions & 8 deletions api/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ pub use table::{RawTableItemRequest, TableItemRequest};
pub use transaction::{
AccountSignature, BlockMetadataTransaction, DeleteModule, DeleteResource, DeleteTableItem,
DirectWriteSet, Ed25519Signature, EncodeSubmissionRequest, EntryFunctionPayload, Event,
GasEstimation, GasEstimationBcs, GenesisPayload, GenesisTransaction, ModuleBundlePayload,
MultiAgentSignature, MultiEd25519Signature, MultisigPayload, MultisigTransactionPayload,
PendingTransaction, ScriptPayload, ScriptWriteSet, SubmitTransactionRequest, Transaction,
TransactionData, TransactionId, TransactionInfo, TransactionOnChainData, TransactionPayload,
TransactionSignature, TransactionSigningMessage, TransactionsBatchSingleSubmissionFailure,
TransactionsBatchSubmissionResult, UserCreateSigningMessageRequest, UserTransaction,
UserTransactionRequest, VersionedEvent, WriteModule, WriteResource, WriteSet, WriteSetChange,
WriteSetPayload, WriteTableItem,
FeePayerSignature, GasEstimation, GasEstimationBcs, GenesisPayload, GenesisTransaction,
ModuleBundlePayload, MultiAgentSignature, MultiEd25519Signature, MultisigPayload,
MultisigTransactionPayload, PendingTransaction, ScriptPayload, ScriptWriteSet,
SubmitTransactionRequest, Transaction, TransactionData, TransactionId, TransactionInfo,
TransactionOnChainData, TransactionPayload, TransactionSignature, TransactionSigningMessage,
TransactionsBatchSingleSubmissionFailure, TransactionsBatchSubmissionResult,
UserCreateSigningMessageRequest, UserTransaction, UserTransactionRequest, VersionedEvent,
WriteModule, WriteResource, WriteSet, WriteSetChange, WriteSetPayload, WriteTableItem,
};
pub use view::ViewRequest;
pub use wrappers::{EventGuid, IdentifierWrapper, StateKeyWrapper};
Expand Down
Loading

0 comments on commit 604cb4f

Please sign in to comment.