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

fix (fuel-indexer,fuel-indexer-types): Re-integrate block producer #430

Merged
merged 3 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
716 changes: 647 additions & 69 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/src/indexing/blocks-and-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ You can index use the `BlockData` and `TransactionData` data structures to index
pub struct BlockData {
pub height: u64,
pub id: Bytes32,
pub producer: Option<Bytes32>,
pub time: i64,
pub transactions: Vec<TransactionData>,
}
```

The `BlockData` struct is how blocks are represented in the Fuel indexer. It contains metadata such as the ID, height, and time, as well as a list of the transactions it contains (represented by `TransactionData`).
The `BlockData` struct is how blocks are represented in the Fuel indexer. It contains metadata such as the ID, height, and time, as well as a list of the transactions it contains (represented by `TransactionData`). It also contains the public key hash of the block producer, if present.

## `TransactionData`

Expand Down
6 changes: 3 additions & 3 deletions examples/block-explorer/explorer-index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ mod explorer_index {
// a block entity `Block` that we can persist to the database. The `Block` type below is
// defined in our schema/explorer.graphql and represents the type that we will
// save to our database.
//
// Note: There is no miner/producer address for blocks in this example; the producer field
// was removed from the `Block` struct as part of fuel-core v0.12.
let producer = block_data.producer.unwrap_or(Bytes32::zeroed());

let block = Block {
id: block_data.id,
height: block_data.height,
producer,
timestamp: block_data.time,
gas_limit: block_gas_limit,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type QueryRoot {
type Block {
id: Bytes32! @unique
height: UInt8!
producer: Bytes32!
timestamp: Int8!
gas_limit: UInt8!
}
Expand Down
6 changes: 3 additions & 3 deletions examples/hello-world/hello-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ fuel-indexer-lib = { version = "0.1", path = "../../../packages/fuel-indexer-lib
fuel-indexer-tests = { version = "0.0.0", path = "./../../../packages/fuel-indexer-tests" }
fuel-tx = "0.23"
fuel-types = "0.5"
fuels = { version = "0.30", features = ["fuel-core-lib"] }
fuels-abigen-macro = "0.30"
fuels-core = { version = "0.30", default-features = false }
fuels = { version = "0.32", features = ["fuel-core-lib"] }
fuels-abigen-macro = "0.32"
fuels-core = { version = "0.32", default-features = false }
rand = "0.8"
thiserror = "1.0"
tokio = { version = "1.17", features = ["macros", "rt-multi-thread"] }
6 changes: 3 additions & 3 deletions packages/fuel-indexer-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ fuel-indexer-sqlite = { version = "0.1", path = "./../fuel-indexer-database/sqli
fuel-indexer-types = { version = "0.1", path = "./../fuel-indexer-types" }
fuel-tx = "0.23"
fuel-types = "0.5"
fuels = { version = "0.30", features = ["fuel-core-lib"] }
fuels-abigen-macro = "0.30"
fuels-core = "0.30"
fuels = { version = "0.32", features = ["fuel-core-lib"] }
fuels-abigen-macro = "0.32"
fuels-core = "0.32"
futures = "0.3"
hex = "0.4"
itertools = "0.10"
Expand Down
Binary file modified packages/fuel-indexer-tests/assets/explorer_index.wasm
Binary file not shown.
Binary file modified packages/fuel-indexer-tests/assets/fuel_indexer_test.wasm
Binary file not shown.
Binary file modified packages/fuel-indexer-tests/assets/simple_wasm.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions packages/fuel-indexer-tests/components/web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ fuel-indexer-lib = { version = "0.1", path = "../../../fuel-indexer-lib" }
fuel-indexer-tests = { version = "0.0.0", path = "./../../../fuel-indexer-tests" }
fuel-tx = "0.23"
fuel-types = "0.5"
fuels = { version = "0.30", features = ["fuel-core-lib"] }
fuels-abigen-macro = "0.30"
fuels-core = { version = "0.30", default-features = false }
fuels = { version = "0.32", features = ["fuel-core-lib"] }
fuels-abigen-macro = "0.32"
fuels-core = { version = "0.32", default-features = false }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use fuel_indexer_tests::{
defaults,
fixtures::{get_contract_id, tx_params},
};
use fuels::fuels_abigen::abigen;
use fuels::prelude::CallParameters;
use fuels_abigen_macro::abigen;
use std::path::Path;
use tracing::info;

Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-indexer-tests/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use fuel_indexer_database::IndexerConnectionPool;
use fuel_indexer_lib::config::{
DatabaseConfig, FuelNodeConfig, GraphQLConfig, IndexerConfig,
};
use fuels::core::parameters::StorageConfiguration;
use fuels::{
prelude::{
setup_single_asset_coins, setup_test_client, AssetId, Bech32ContractId, Config,
Contract, Provider, TxParameters, WalletUnlocked, DEFAULT_COIN_AMOUNT,
},
signers::Signer,
};
use fuels_core::parameters::StorageConfiguration;
use sqlx::{
pool::{Pool, PoolConnection},
Postgres, Sqlite,
Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-indexer-tests/tests/integration/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use fuel_indexer_tests::{
defaults,
fixtures::{indexer_service_postgres, tx_params},
};
use fuels::core::parameters::StorageConfiguration;
use fuels::fuels_abigen::abigen;
use fuels::prelude::{
setup_single_asset_coins, setup_test_client, AssetId, Contract, Provider,
WalletUnlocked, DEFAULT_COIN_AMOUNT,
};
use fuels::signers::Signer;
use fuels_abigen_macro::abigen;
use fuels_core::parameters::StorageConfiguration;
use std::path::Path;

const SIMPLE_WASM_MANIFEST: &str = include_str!("./../../assets/macros/simple_wasm.yaml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn main() {
let data: Vec<BlockData> = vec![BlockData {
id: [0u8; 32].into(),
time: 1,
producer: None,
height: 0,
transactions: vec![TransactionData {
id: [0u8; 32].into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn main() {
let data: Vec<BlockData> = vec![BlockData {
id: [0u8; 32].into(),
time: 1,
producer: None,
height: 0,
transactions: vec![TransactionData {
status: TransactionStatus::default(),
Expand Down
1 change: 1 addition & 0 deletions packages/fuel-indexer-types/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct TransactionData {
pub struct BlockData {
pub height: u64,
pub id: Bytes32,
pub producer: Option<Bytes32>,
pub time: i64,
pub transactions: Vec<TransactionData>,
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bincode = "1.3.3"
cfg-if = "1.0"
chrono = { version = "0.4", features = ["serde"] }
clap = { version = "3.1", features = ["cargo", "derive", "env"] }
fuel-gql-client = { version = "0.14" }
fuel-gql-client = { version = "0.15" }
fuel-indexer-api-server = { version = "0.1", path = "../fuel-indexer-api-server", optional = true }
fuel-indexer-database = { version = "0.1", path = "../fuel-indexer-database" }
fuel-indexer-database-types = { version = "0.1", path = "../fuel-indexer-database/database-types" }
Expand Down Expand Up @@ -48,7 +48,7 @@ wasmer-engine-universal = "2.0"
[dev-dependencies]
chrono = { version = "0.4", features = ["serde"] }
fuel-crypto = "0.6"
fuel-gql-client = { version = "0.14", features = ["test-helpers"] }
fuel-gql-client = { version = "0.15", features = ["test-helpers"] }
fuel-types = "0.5"
itertools = { version = "0.10" }
rand = "0.8"
Expand Down
3 changes: 3 additions & 0 deletions packages/fuel-indexer/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ fn run_executor<T: 'static + Executor + Send + Sync>(

let mut block_info = Vec::new();
for block in results.into_iter().rev() {
let producer = block.block_producer().map(|pk| pk.hash());

// NOTE: for now assuming we have a single contract instance,
// we'll need to watch contract creation events here in
// case an indexer would be interested in processing it.
Expand Down Expand Up @@ -245,6 +247,7 @@ fn run_executor<T: 'static + Executor + Send + Sync>(
let block = BlockData {
height: block.header.height.0,
id: Bytes32::from(block.id),
producer,
time: block.header.time.0.to_unix(),
transactions,
};
Expand Down