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

Support nearcore 1.37 #169

Closed
wants to merge 11 commits into from
Closed
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
2,848 changes: 882 additions & 1,966 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,3 @@ members = [
"state-indexer",
"tx-indexer",
]

[patch.crates-io]
near-chain-configs = { git = 'https://github.com/near/nearcore.git', branch = '1.36.0' }
near-crypto = { git = 'https://github.com/near/nearcore.git', branch = '1.36.0' }
near-jsonrpc-primitives = { git = 'https://github.com/near/nearcore.git', branch = '1.36.0' }
near-indexer-primitives = { git = 'https://github.com/near/nearcore.git', branch = '1.36.0' }
near-primitives = { git = 'https://github.com/near/nearcore.git', branch = '1.36.0' }
near-vm-runner = { git = 'https://github.com/near/nearcore.git', branch = '1.36.0' }

# TODO: We use forks to resolve nearcore dependency conflicts.
# After updating the dependencies, we should use the published versions of the crates.
near-jsonrpc-client = { git = 'https://github.com/kobayurii/near-jsonrpc-client-rs.git', branch = '0.7.0' }
near-lake-framework = { git = 'https://github.com/kobayurii/near-lake-framework-rs.git', branch = '0.7.9' }
8 changes: 4 additions & 4 deletions configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ license.workspace = true

[dependencies]
anyhow = "1.0.70"
aws-credential-types = "1.0.0"
aws-sdk-s3 = { version = "0.39.1", features = ["behavior-version-latest"] }
aws-types = "1.0.0"
aws-credential-types = "1.1.4"
aws-sdk-s3 = { version = "1.14.0", features = ["behavior-version-latest"] }
aws-types = "1.1.4"
dotenv = "0.15.0"
lazy_static = "1.4.0"
regex = "1.10.2"
Expand All @@ -35,7 +35,7 @@ tracing-subscriber = { version = "0.3.15", features = [
tracing-opentelemetry = { version = "0.19", optional = true }
tracing-stackdriver = "0.7.2" # GCP logs

near-lake-framework = "0.7.9"
near-lake-framework = "0.7.7"

[features]
tracing-instrumentation = ["dep:opentelemetry-jaeger", "dep:tracing-opentelemetry"]
23 changes: 12 additions & 11 deletions database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,40 @@ license.workspace = true
anyhow = "1.0.70"
async-trait = "0.1.66"
bigdecimal = { version = "0.4.2", optional = true }
borsh = "0.10.2"
bytes = "1.0.1"
borsh = "1.3.1"
bytes = "1.5.0"
diesel = { version = "2.1.3", features = ["postgres", "numeric", "serde_json"], optional = true }
diesel-async = { version = "0.4.1", features = ["postgres", "deadpool"], optional = true }
diesel_migrations = { version = "2.1.0", optional = true }
futures = "0.3.5"
hex = "0.4.3"
prettytable-rs = { version = "0.10", optional = true }
num-bigint = { version = "0.3", optional = true }
num-bigint = { version = "0.4.4", optional = true }
num-traits = { version = "0.2.15", optional = true }
scylla = { version = "0.9.0", optional = true }
scylla = { version = "0.12.0", features = ["full-serialization"], optional = true }
scylla-cql = { version = "0.1.0", optional = true }
serde = { version = "1.0.145", features = ["derive"]}
serde_json = "1.0.85"
tokio = { version = "1.19.2", features = [
tokio = { version = "1.36.0", features = [
"sync",
"time",
"macros",
"rt-multi-thread",
] }
tracing = "0.1.34"
uuid = { version = "1.3.0", optional = true }
uuid = { version = "1.7.0", optional = true }

configuration = { path = "../configuration" }
readnode-primitives = { path = "../readnode-primitives" }

near-chain-configs = "1.36.0"
near-primitives = "1.36.0"
near-crypto = "1.36.0"
near-indexer-primitives = "1.36.0"
near-chain-configs = "0.20.0"
near-primitives = "0.20.0"
near-crypto = "0.20.0"
near-indexer-primitives = "0.20.0"

[features]
default = ["scylla_db"]
postgres_db = ["dep:diesel", "dep:diesel-async", "dep:diesel_migrations", "dep:bigdecimal"]
scylla_db = ["dep:scylla", "dep:num-bigint", "dep:num-traits"]
scylla_db = ["dep:scylla", "dep:scylla-cql", "dep:num-bigint", "dep:num-traits"]
scylla_db_tracing = ["dep:prettytable-rs", "dep:uuid", "scylla_db"]
account_access_keys = []
6 changes: 0 additions & 6 deletions database/src/base/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,4 @@ pub trait ReaderDbManager {
&self,
block_height: near_primitives::types::BlockHeight,
) -> anyhow::Result<readnode_primitives::EpochValidatorsInfo>;

/// Return protocol config by the given epoch id
async fn get_protocol_config_by_epoch_id(
&self,
epoch_id: near_primitives::hash::CryptoHash,
) -> anyhow::Result<near_chain_configs::ProtocolConfigView>;
}
8 changes: 0 additions & 8 deletions database/src/base/state_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,6 @@ pub trait StateIndexerDbManager {
validators_info: &near_primitives::views::EpochValidatorInfo,
) -> anyhow::Result<()>;

async fn add_protocol_config(
&self,
epoch_id: near_indexer_primitives::CryptoHash,
epoch_height: u64,
epoch_start_height: u64,
protocol_config: &near_chain_configs::ProtocolConfigView,
) -> anyhow::Result<()>;

async fn update_epoch_end_height(
&self,
epoch_id: near_indexer_primitives::CryptoHash,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS protocol_configs (
epoch_id text NOT NULL,
epoch_height numeric(20,0) NOT NULL,
epoch_start_height numeric(20,0) NOT NULL,
epoch_end_height numeric(20,0) NULL,
protocol_config jsonb NOT NULL
);

ALTER TABLE ONLY protocol_configs
ADD CONSTRAINT protocol_config_pk PRIMARY KEY (epoch_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS protocol_configs;
55 changes: 2 additions & 53 deletions database/src/postgres/models.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::schema::*;
use borsh::{BorshDeserialize, BorshSerialize};
use diesel::prelude::*;
use diesel_async::RunQueryDsl;

Expand Down Expand Up @@ -362,7 +361,7 @@ impl AccountState {
page_token: crate::PageToken,
) -> anyhow::Result<(Vec<String>, crate::PageToken)> {
let page_state = if let Some(page_state_token) = page_token {
PageState::try_from_slice(&hex::decode(page_state_token)?)?
borsh::from_slice::<PageState>(&hex::decode(page_state_token)?)?
} else {
PageState::new(1000)
};
Expand All @@ -384,7 +383,7 @@ impl AccountState {
} else {
Ok((
state_keys,
Some(hex::encode(page_state.next_page().try_to_vec()?)),
Some(hex::encode(borsh::to_vec(&page_state.next_page())?)),
))
}
}
Expand Down Expand Up @@ -735,53 +734,3 @@ impl Validators {
Ok(response)
}
}

#[derive(Insertable, Queryable, Selectable)]
#[diesel(table_name = protocol_configs)]
pub struct ProtocolConfig {
pub epoch_id: String,
pub epoch_height: bigdecimal::BigDecimal,
pub epoch_start_height: bigdecimal::BigDecimal,
pub epoch_end_height: Option<bigdecimal::BigDecimal>,
pub protocol_config: serde_json::Value,
}

impl ProtocolConfig {
pub async fn insert_or_ignore(
&self,
mut conn: crate::postgres::PgAsyncConn,
) -> anyhow::Result<()> {
diesel::insert_into(protocol_configs::table)
.values(self)
.on_conflict_do_nothing()
.execute(&mut conn)
.await?;
Ok(())
}

pub async fn update_epoch_end_height(
mut conn: crate::postgres::PgAsyncConn,
epoch_id: near_indexer_primitives::CryptoHash,
epoch_end_height: bigdecimal::BigDecimal,
) -> anyhow::Result<()> {
diesel::update(protocol_configs::table)
.filter(protocol_configs::epoch_id.eq(epoch_id.to_string()))
.set(protocol_configs::epoch_end_height.eq(epoch_end_height))
.execute(&mut conn)
.await?;
Ok(())
}

pub async fn get_protocol_config(
mut conn: crate::postgres::PgAsyncConn,
epoch_id: near_indexer_primitives::CryptoHash,
) -> anyhow::Result<Self> {
let response = protocol_configs::table
.filter(protocol_configs::epoch_id.eq(epoch_id.to_string()))
.select(Self::as_select())
.first(&mut conn)
.await?;

Ok(response)
}
}
51 changes: 15 additions & 36 deletions database/src/postgres/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::str::FromStr;

use crate::postgres::PostgresStorageManager;
use bigdecimal::ToPrimitive;
use borsh::{BorshDeserialize, BorshSerialize};

pub struct PostgresDBManager {
pg_pool: crate::postgres::PgAsyncPool,
Expand Down Expand Up @@ -67,7 +66,7 @@ impl crate::ReaderDbManager for PostgresDBManager {
) -> anyhow::Result<Vec<readnode_primitives::StateKey>> {
let result = crate::models::AccountState::get_state_keys_all(
Self::get_connection(&self.pg_pool).await?,
account_id,
account_id.as_str(),
)
.await?
.into_iter()
Expand All @@ -83,7 +82,7 @@ impl crate::ReaderDbManager for PostgresDBManager {
let hex_str_prefix = hex::encode(prefix);
let result = crate::models::AccountState::get_state_keys_by_prefix(
Self::get_connection(&self.pg_pool).await?,
account_id,
account_id.as_str(),
hex_str_prefix,
)
.await?
Expand All @@ -99,7 +98,7 @@ impl crate::ReaderDbManager for PostgresDBManager {
) -> anyhow::Result<(Vec<readnode_primitives::StateKey>, crate::PageToken)> {
let (state_keys, next_page_token) = crate::models::AccountState::get_state_keys_by_page(
Self::get_connection(&self.pg_pool).await?,
account_id,
account_id.as_str(),
page_token,
)
.await?;
Expand All @@ -126,7 +125,7 @@ impl crate::ReaderDbManager for PostgresDBManager {
};
let result = if let Ok(result) = crate::models::StateChangesData::get_state_key_value(
connection,
account_id,
account_id.as_str(),
block_height,
hex::encode(key_data.clone()),
)
Expand All @@ -146,7 +145,7 @@ impl crate::ReaderDbManager for PostgresDBManager {
) -> anyhow::Result<readnode_primitives::QueryData<near_primitives::account::Account>> {
let account_data = crate::models::StateChangesAccount::get_account(
Self::get_connection(&self.pg_pool).await?,
account_id,
account_id.as_str(),
request_block_height,
)
.await?;
Expand Down Expand Up @@ -176,7 +175,7 @@ impl crate::ReaderDbManager for PostgresDBManager {
) -> anyhow::Result<readnode_primitives::QueryData<Vec<u8>>> {
let contract_data = crate::models::StateChangesContract::get_contract(
Self::get_connection(&self.pg_pool).await?,
account_id,
account_id.as_str(),
request_block_height,
)
.await?;
Expand Down Expand Up @@ -205,10 +204,10 @@ impl crate::ReaderDbManager for PostgresDBManager {
request_block_height: near_primitives::types::BlockHeight,
public_key: near_crypto::PublicKey,
) -> anyhow::Result<readnode_primitives::QueryData<near_primitives::account::AccessKey>> {
let key_data = public_key.try_to_vec()?;
let key_data = borsh::to_vec(&public_key)?;
let access_key_data = crate::models::StateChangesAccessKey::get_access_key(
Self::get_connection(&self.pg_pool).await?,
account_id,
account_id.as_str(),
request_block_height,
hex::encode(key_data),
)
Expand Down Expand Up @@ -241,7 +240,7 @@ impl crate::ReaderDbManager for PostgresDBManager {
) -> anyhow::Result<std::collections::HashMap<String, Vec<u8>>> {
let active_access_keys = crate::models::StateChangesAccessKeys::get_active_access_keys(
Self::get_connection(&self.pg_pool).await?,
&account_id,
account_id.as_str(),
block_height,
)
.await?;
Expand Down Expand Up @@ -293,9 +292,7 @@ impl crate::ReaderDbManager for PostgresDBManager {
transaction_hash,
)
.await?;
Ok(readnode_primitives::TransactionDetails::try_from_slice(
&transaction_data,
)?)
Ok(borsh::from_slice::<readnode_primitives::TransactionDetails>(&transaction_data)?)
}

async fn get_indexing_transaction_by_hash(
Expand All @@ -308,7 +305,7 @@ impl crate::ReaderDbManager for PostgresDBManager {
)
.await?;
let mut transaction_details =
readnode_primitives::CollectingTransactionDetails::try_from_slice(&data_value)?;
borsh::from_slice::<readnode_primitives::CollectingTransactionDetails>(&data_value)?;

let result = crate::models::ReceiptOutcome::get_receipt_outcome(
Self::get_connection(&self.pg_pool).await?,
Expand All @@ -318,13 +315,10 @@ impl crate::ReaderDbManager for PostgresDBManager {
.await?;
for receipt_outcome in result {
let receipt =
near_primitives::views::ReceiptView::try_from_slice(&receipt_outcome.receipt)
.expect("Failed to deserialize receipt");
let execution_outcome =
near_primitives::views::ExecutionOutcomeWithIdView::try_from_slice(
&receipt_outcome.outcome,
)
.expect("Failed to deserialize execution outcome");
borsh::from_slice::<near_primitives::views::ReceiptView>(&receipt_outcome.receipt)?;
let execution_outcome = borsh::from_slice::<
near_primitives::views::ExecutionOutcomeWithIdView,
>(&receipt_outcome.outcome)?;
transaction_details.receipts.push(receipt);
transaction_details
.execution_outcomes
Expand Down Expand Up @@ -414,19 +408,4 @@ impl crate::ReaderDbManager for PostgresDBManager {
validators_info,
})
}

async fn get_protocol_config_by_epoch_id(
&self,
epoch_id: near_indexer_primitives::CryptoHash,
) -> anyhow::Result<near_chain_configs::ProtocolConfigView> {
let protocol_config = crate::models::ProtocolConfig::get_protocol_config(
Self::get_connection(&self.pg_pool).await?,
epoch_id,
)
.await?;
let (protocol_config,) = serde_json::from_value::<(near_chain_configs::ProtocolConfigView,)>(
protocol_config.protocol_config,
)?;
Ok(protocol_config)
}
}
11 changes: 0 additions & 11 deletions database/src/postgres/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ diesel::table! {
}
}

diesel::table! {
protocol_configs (epoch_id) {
epoch_id -> Text,
epoch_height -> Numeric,
epoch_start_height -> Numeric,
epoch_end_height -> Nullable<Numeric>,
protocol_config -> Jsonb,
}
}

diesel::table! {
receipt_map (receipt_id) {
receipt_id -> Text,
Expand Down Expand Up @@ -138,7 +128,6 @@ diesel::allow_tables_to_appear_in_same_query!(
block,
chunk,
meta,
protocol_configs,
receipt_map,
receipt_outcome,
state_changes_access_key,
Expand Down
Loading
Loading