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

Account-base fee collection #1407

Merged
merged 16 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Description of the upcoming release here.
- [#1395](https://github.com/FuelLabs/fuel-core/pull/1395): Add DependentCost benchmarks for `k256`, `s256` and `mcpi` instructions.

#### Breaking
- [#1407](https://github.com/FuelLabs/fuel-core/pull/1407): The recipient is a `ContractId` instead of `Address`. The block producer should deploy its contract to receive the transaction fee. The collected fee is zero until the recipient contract is set.
- [#1407](https://github.com/FuelLabs/fuel-core/pull/1407): The `Mint` transaction is reworked with new fields to support the account-base model. It affects serialization and deserialization of the transaction and also affects GraphQL schema.
- [#1407](https://github.com/FuelLabs/fuel-core/pull/1407): The `Mint` transaction is the last transaction in the block instead of the first.
- [#1374](https://github.com/FuelLabs/fuel-core/pull/1374): Renamed `base_chain_height` to `da_height` and return current relayer height instead of latest Fuel block height.
- [#1363](https://github.com/FuelLabs/fuel-core/pull/1363): Change message_proof api to take `nonce` instead of `message_id`
- [#1339](https://github.com/FuelLabs/fuel-core/pull/1339): Added a new required field called `base_asset_id` to the `FeeParameters` definition in `ConsensusParameters`, as well as default values for `base_asset_id` in the `beta` and `dev` chainspecs.
Expand Down
24 changes: 8 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ itertools = "0.10"
insta = "1.8"
tempfile = "3.4"
tikv-jemallocator = "0.5"

[patch.crates-io]
fuel-vm = { git = "https://github.com/FuelLabs/fuel-vm/", branch = "feature/mint-tx-rework-contract" }
23 changes: 8 additions & 15 deletions bin/fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ use fuel_core::{
txpool::Config as TxPoolConfig,
types::{
blockchain::primitives::SecretKeyWrapper,
fuel_tx::Address,
fuel_tx::ContractId,
fuel_vm::SecretKey,
secrecy::{
ExposeSecret,
Secret,
},
secrecy::Secret,
},
};
use pyroscope::{
Expand All @@ -47,7 +44,6 @@ use pyroscope_pprofrs::{
use std::{
env,
net,
ops::Deref,
path::PathBuf,
str::FromStr,
};
Expand Down Expand Up @@ -285,16 +281,13 @@ impl Command {
}

let coinbase_recipient = if let Some(coinbase_recipient) = coinbase_recipient {
Address::from_str(coinbase_recipient.as_str()).map_err(|err| anyhow!(err))?
Some(
ContractId::from_str(coinbase_recipient.as_str())
.map_err(|err| anyhow!(err))?,
)
} else {
consensus_key
.as_ref()
.cloned()
.map(|key| {
let sk = key.expose_secret().deref();
Address::from(*sk.public_key().hash())
})
.unwrap_or_default()
tracing::warn!("The coinbase recipient `ContractId` is not set!");
None
};

let verifier = RelayerVerifierConfig {
Expand Down
4 changes: 4 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -840,15 +840,19 @@ type Transaction {
id: TransactionId!
inputAssetIds: [AssetId!]
inputContracts: [Contract!]
inputContract: InputContract
gasPrice: U64
gasLimit: U64
maturity: U32
mintAmount: U64
mintAssetId: AssetId
txPointer: TxPointer
isScript: Boolean!
isCreate: Boolean!
isMint: Boolean!
inputs: [Input!]
outputs: [Output!]!
outputContract: ContractOutput
witnesses: [HexString!]
receiptsRoot: Bytes32
status: TransactionStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ query($id: TransactionId!) {
inputContracts {
id
}
inputContract {
utxoId
balanceRoot
stateRoot
txPointer
contract {
id
}
}
inputs {
__typename
... on InputCoin {
Expand Down Expand Up @@ -79,7 +88,14 @@ query($id: TransactionId!) {
stateRoot
}
}
outputContract {
inputIndex
balanceRoot
stateRoot
}
maturity
mintAmount
mintAssetId
receiptsRoot
status {
__typename
Expand Down
68 changes: 52 additions & 16 deletions crates/client/src/client/schema/tx/transparent_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use fuel_core_types::{
fuel_tx,
fuel_tx::{
field::ReceiptsRoot,
input,
output,
StorageSlot,
},
fuel_types,
Expand Down Expand Up @@ -81,12 +83,16 @@ pub struct Transaction {
pub tx_pointer: Option<TxPointer>,
pub input_asset_ids: Option<Vec<AssetId>>,
pub input_contracts: Option<Vec<ContractIdFragment>>,
pub input_contract: Option<InputContract>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have input_contracts as well as input_contract?

From reading the code, it looks like input_contracts is used for Script and Create transactions (or anything that is not a Mint transaction), while input_contract is used for Mint transactions.

Maybe it would be helpful to change the names to better describe their usage and/or add some comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any update here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added the comments into the code itself=)

pub inputs: Option<Vec<Input>>,
pub is_script: bool,
pub is_create: bool,
pub is_mint: bool,
pub outputs: Vec<Output>,
pub output_contract: Option<ContractOutput>,
pub maturity: Option<U32>,
pub mint_amount: Option<U64>,
pub mint_asset_id: Option<AssetId>,
pub receipts_root: Option<Bytes32>,
pub status: Option<TransactionStatus>,
pub witnesses: Option<Vec<HexString>>,
Expand Down Expand Up @@ -220,10 +226,26 @@ impl TryFrom<Transaction> for fuel_tx::Transaction {
.into();
let mint = fuel_tx::Transaction::mint(
tx_pointer,
tx.outputs
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<fuel_tx::Output>, ConversionError>>()?,
tx.input_contract
.ok_or_else(|| {
ConversionError::MissingField("input_contract".to_string())
})?
.into(),
tx.output_contract
.ok_or_else(|| {
ConversionError::MissingField("output_contract".to_string())
})?
.try_into()?,
tx.mint_amount
.ok_or_else(|| {
ConversionError::MissingField("mint_amount".to_string())
})?
.into(),
tx.mint_asset_id
.ok_or_else(|| {
ConversionError::MissingField("mint_asset_id".to_string())
})?
.into(),
);
mint.into()
};
Expand Down Expand Up @@ -321,13 +343,7 @@ impl TryFrom<Input> for fuel_tx::Input {
)
}
}
Input::InputContract(contract) => fuel_tx::Input::contract(
contract.utxo_id.into(),
contract.balance_root.into(),
contract.state_root.into(),
contract.tx_pointer.into(),
contract.contract.id.into(),
),
Input::InputContract(contract) => fuel_tx::Input::Contract(contract.into()),
Input::InputMessage(message) => {
match (
message.data.0 .0.is_empty(),
Expand Down Expand Up @@ -435,11 +451,7 @@ impl TryFrom<Output> for fuel_tx::Output {
amount: coin.amount.into(),
asset_id: coin.asset_id.into(),
},
Output::ContractOutput(contract) => Self::Contract {
input_index: contract.input_index.try_into()?,
balance_root: contract.balance_root.into(),
state_root: contract.state_root.into(),
},
Output::ContractOutput(contract) => Self::Contract(contract.try_into()?),
Output::ChangeOutput(change) => Self::Change {
to: change.to.into(),
amount: change.amount.into(),
Expand All @@ -458,3 +470,27 @@ impl TryFrom<Output> for fuel_tx::Output {
})
}
}

impl From<InputContract> for input::contract::Contract {
fn from(contract: InputContract) -> Self {
input::contract::Contract {
utxo_id: contract.utxo_id.into(),
balance_root: contract.balance_root.into(),
state_root: contract.state_root.into(),
tx_pointer: contract.tx_pointer.into(),
contract_id: contract.contract.id.into(),
}
}
}

impl TryFrom<ContractOutput> for output::contract::Contract {
type Error = ConversionError;

fn try_from(contract: ContractOutput) -> Result<Self, Self::Error> {
Ok(output::contract::Contract {
input_index: contract.input_index.try_into()?,
balance_root: contract.balance_root.into(),
state_root: contract.state_root.into(),
})
}
}
7 changes: 3 additions & 4 deletions crates/fuel-core/src/database/vm_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use fuel_core_types::{
StorageSlot,
},
fuel_types::{
Address,
BlockHeight,
Bytes32,
ContractId,
Expand All @@ -45,7 +44,7 @@ use std::borrow::Cow;
pub struct VmDatabase {
current_block_height: BlockHeight,
current_timestamp: Tai64,
coinbase: Address,
coinbase: ContractId,
database: Database,
}

Expand Down Expand Up @@ -77,7 +76,7 @@ impl VmDatabase {
pub fn new<T>(
database: Database,
header: &ConsensusHeader<T>,
coinbase: Address,
coinbase: ContractId,
) -> Self {
Self {
current_block_height: header.height,
Expand Down Expand Up @@ -194,7 +193,7 @@ impl InterpreterStorage for VmDatabase {
}
}

fn coinbase(&self) -> Result<Address, Self::DataError> {
fn coinbase(&self) -> Result<ContractId, Self::DataError> {
Ok(self.coinbase)
}

Expand Down
Loading
Loading