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 8 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 = "master" }
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions benches/benches/set/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ pub fn run(c: &mut Criterion) {
let coin_output = Output::variable(Address::zeroed(), 100, AssetId::zeroed());
input.outputs.push(coin_output);
let predicate = op::ret(RegId::ONE).to_bytes().to_vec();
let owner = Input::predicate_owner(&predicate, &ChainId::default());
let owner = Input::predicate_owner(&predicate);
let coin_input = Input::coin_predicate(
Default::default(),
owner,
Expand Down Expand Up @@ -455,7 +455,7 @@ pub fn run(c: &mut Criterion) {
.chain(vec![2u8; i as usize]),
);
let predicate = op::ret(RegId::ONE).to_bytes().to_vec();
let owner = Input::predicate_owner(&predicate, &ChainId::default());
let owner = Input::predicate_owner(&predicate);
let coin_input = Input::coin_predicate(
Default::default(),
owner,
Expand Down
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
72 changes: 56 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 @@ -80,13 +82,21 @@ pub struct Transaction {
pub id: TransactionId,
pub tx_pointer: Option<TxPointer>,
pub input_asset_ids: Option<Vec<AssetId>>,
/// The list of all contracts from the inputs of the transaction.
///
/// It is a helper function and doesn't have a corresponding field in the transaction.
Copy link
Member

Choose a reason for hiding this comment

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

What is the "helper function"? This is a field on a struct.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. The function isn't public though, but this doc comment is public, so maybe mentioning the function isn't necessary as long as you say it's generated rather than part of the original Transaction.

pub input_contracts: Option<Vec<ContractIdFragment>>,
/// The field of the `Mint` transaction.
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved
pub input_contract: Option<InputContract>,
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 +230,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 +347,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 +455,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 +474,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