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

feat: global contract usage #12886

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d81c640
global contract support
stedfn Feb 5, 2025
05887a2
remove duplicate
stedfn Feb 5, 2025
f2fd27b
clippy
stedfn Feb 5, 2025
498a9ad
.
stedfn Feb 5, 2025
a95fe45
simplify
stedfn Feb 5, 2025
625d592
.
stedfn Feb 5, 2025
e4b30e6
fix
stedfn Feb 5, 2025
b2d8efa
schema
stedfn Feb 5, 2025
e73e9d9
address comments
stedfn Feb 6, 2025
506d964
schema
stedfn Feb 6, 2025
f995762
Merge branch 'master' into stefan/global_contract_account_support
stedfn Feb 6, 2025
a285285
fix
stedfn Feb 6, 2025
28c6ea1
comments
stedfn Feb 6, 2025
115b53d
fmt
stedfn Feb 6, 2025
6baaef7
style
stedfn Feb 6, 2025
0cc098a
.
stedfn Feb 6, 2025
4d9bbc9
reference todo
stedfn Feb 6, 2025
e73e627
.
stedfn Feb 6, 2025
897985e
comments
stedfn Feb 6, 2025
102e4a9
comments
stedfn Feb 7, 2025
b4f5ed9
introduce local_contract_hash
stedfn Feb 7, 2025
f24d365
Merge branch 'master' into stefan/global_contract_account_support
stedfn Feb 7, 2025
ad1f781
rename tests
stedfn Feb 7, 2025
1ca7b96
Merge branch 'stefan/global_contract_account_support' of github.com:n…
stedfn Feb 7, 2025
0d24479
wip
stedfn Feb 7, 2025
8751cb6
Merge branch 'stefan/global_contract_account_support' into stefan/glo…
stedfn Feb 7, 2025
dd266a7
wip
stedfn Feb 7, 2025
e981c09
deploy global contract
stedfn Feb 7, 2025
cdc92ef
merge
stedfn Feb 10, 2025
f747bb8
.
stedfn Feb 10, 2025
067c5bb
remove useless fn
stedfn Feb 10, 2025
9db880d
impl errors
stedfn Feb 10, 2025
037611a
Revert "remove useless fn"
stedfn Feb 10, 2025
139f5ff
mvp
stedfn Feb 11, 2025
40e9976
Merge branch 'master' into stefan/global_contract_usage
stedfn Feb 11, 2025
5f10308
test wip failing
stedfn Feb 11, 2025
c4e603a
remove debug logs
stedfn Feb 11, 2025
d3cf5ed
remove logs
stedfn Feb 11, 2025
713d0b6
tests
stedfn Feb 11, 2025
6500dde
remove comment
stedfn Feb 11, 2025
b4c4c2f
fix
stedfn Feb 11, 2025
a1eed5b
move tests behind nightly_protocol feature
stedfn Feb 11, 2025
157b0f9
Merge branch 'master' into stefan/global_contract_usage
stedfn Feb 12, 2025
be89a14
remove get_global_code fn and update errors
stedfn Feb 12, 2025
71cca08
.
stedfn Feb 12, 2025
fc319ce
consider global contract deployment receipt cost
stedfn Feb 13, 2025
f771c89
address comments
stedfn Feb 14, 2025
bc20a98
remove log
stedfn Feb 14, 2025
48a5d4f
Merge branch 'master' into stefan/global_contract_usage
stedfn Feb 14, 2025
41239c1
add new field in BalanceStats for gas burnt by global actions
stedfn Feb 14, 2025
0d07078
comments
stedfn Feb 14, 2025
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
1 change: 1 addition & 0 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 chain/chain/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ impl NightshadeRuntime {
// TODO(#2152): process gracefully
RuntimeError::ReceiptValidationError(e) => panic!("{}", e),
RuntimeError::ValidatorError(e) => e.into(),
RuntimeError::GlobalContractError(_e) => {
todo!()
}
})?;
let elapsed = instant.elapsed();

Expand Down
4 changes: 2 additions & 2 deletions chain/chain/src/test_utils/kv_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use near_crypto::{KeyType, PublicKey, SecretKey};
use near_epoch_manager::EpochManagerAdapter;
use near_parameters::RuntimeConfig;
use near_pool::types::TransactionGroupIterator;
use near_primitives::account::{AccessKey, Account};
use near_primitives::account::{AccessKey, Account, AccountContract};
use near_primitives::apply::ApplyChunkReason;
use near_primitives::bandwidth_scheduler::BandwidthRequests;
use near_primitives::block::Tip;
Expand Down Expand Up @@ -1214,7 +1214,7 @@ impl RuntimeAdapter for KeyValueRuntime {
|state| *state.amounts.get(account_id).unwrap_or(&0),
),
0,
CryptoHash::default(),
AccountContract::None,
0,
)
.into(),
Expand Down
3 changes: 3 additions & 0 deletions chain/jsonrpc/jsonrpc-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ near-jsonrpc-primitives.workspace = true

[dev-dependencies]
near-actix-test-utils.workspace = true
near-primitives-core.workspace = true

[features]
test_features = ["near-jsonrpc/test_features"]
Expand All @@ -45,6 +46,7 @@ nightly = [
"near-jsonrpc/nightly",
"near-network/nightly",
"near-o11y/nightly",
"near-primitives-core/nightly",
"near-primitives/nightly",
"near-store/nightly",
"nightly_protocol",
Expand All @@ -58,6 +60,7 @@ nightly_protocol = [
"near-jsonrpc/nightly_protocol",
"near-network/nightly_protocol",
"near-o11y/nightly_protocol",
"near-primitives-core/nightly_protocol",
"near-primitives/nightly_protocol",
"near-store/nightly_protocol",
]
Expand Down
8 changes: 6 additions & 2 deletions chain/jsonrpc/jsonrpc-tests/tests/rpc_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ fn test_query_by_path_account() {
panic!("queried account, but received something else: {:?}", query_response.kind);
};
assert_eq!(account_info.amount, 0);
assert_eq!(account_info.code_hash.as_ref(), &[0; 32]);
assert_eq!(account_info.code_hash, CryptoHash::default());
assert_eq!(account_info.locked, 0);
assert_eq!(account_info.storage_paid_at, 0);
assert_eq!(account_info.storage_usage, 0);
assert_eq!(account_info.global_contract_hash, None);
assert_eq!(account_info.global_contract_account_id, None);
});
}

Expand Down Expand Up @@ -192,10 +194,12 @@ fn test_query_account() {
panic!("queried account, but received something else: {:?}", query_response.kind);
};
assert_eq!(account_info.amount, 0);
assert_eq!(account_info.code_hash.as_ref(), &[0; 32]);
assert_eq!(account_info.code_hash, CryptoHash::default());
assert_eq!(account_info.locked, 0);
assert_eq!(account_info.storage_paid_at, 0);
assert_eq!(account_info.storage_usage, 0);
assert_eq!(account_info.global_contract_hash, None);
assert_eq!(account_info.global_contract_account_id, None);
}
});
}
Expand Down
25 changes: 19 additions & 6 deletions chain/rosetta-rpc/src/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ mod tests {
use near_crypto::{KeyType, SecretKey};
use near_parameters::{RuntimeConfig, RuntimeConfigView};
use near_primitives::action::delegate::{DelegateAction, SignedDelegateAction};
use near_primitives::hash::CryptoHash;
use near_primitives::transaction::{Action, TransferAction};
use near_time::Clock;

Expand All @@ -865,10 +866,12 @@ mod tests {
account_id: "nfvalidator1.near".parse().unwrap(),
account: near_primitives::views::AccountView {
amount: 5000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
code_hash: CryptoHash::default(),
locked: 400000000000000000000000000000,
storage_paid_at: 0,
storage_usage: 200000,
global_contract_hash: None,
global_contract_account_id: None,
},
},
},
Expand All @@ -880,10 +883,12 @@ mod tests {
account_id: "nfvalidator1.near".parse().unwrap(),
account: near_primitives::views::AccountView {
amount: 4000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
code_hash: CryptoHash::default(),
locked: 400000000000000000000000000000,
storage_paid_at: 0,
storage_usage: 200000,
global_contract_hash: None,
global_contract_account_id: None,
},
},
},
Expand All @@ -893,10 +898,12 @@ mod tests {
account_id: "nfvalidator2.near".parse().unwrap(),
account: near_primitives::views::AccountView {
amount: 7000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
code_hash: CryptoHash::default(),
locked: 400000000000000000000000000000,
storage_paid_at: 0,
storage_usage: 200000,
global_contract_hash: None,
global_contract_account_id: None,
},
},
},
Expand All @@ -908,10 +915,12 @@ mod tests {
account_id: "nfvalidator2.near".parse().unwrap(),
account: near_primitives::views::AccountView {
amount: 8000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
code_hash: CryptoHash::default(),
locked: 400000000000000000000000000000,
storage_paid_at: 0,
storage_usage: 200000,
global_contract_hash: None,
global_contract_account_id: None,
},
},
},
Expand All @@ -921,20 +930,24 @@ mod tests {
"nfvalidator1.near".parse().unwrap(),
near_primitives::views::AccountView {
amount: 4000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
code_hash: CryptoHash::default(),
locked: 400000000000000000000000000000,
storage_paid_at: 0,
storage_usage: 200000,
global_contract_hash: None,
global_contract_account_id: None,
},
);
accounts_previous_state.insert(
"nfvalidator2.near".parse().unwrap(),
near_primitives::views::AccountView {
amount: 6000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
code_hash: CryptoHash::default(),
locked: 400000000000000000000000000000,
storage_paid_at: 0,
storage_usage: 200000,
global_contract_hash: None,
global_contract_account_id: None,
},
);
let transactions = super::transactions::convert_block_changes_to_transactions(
Expand Down
4 changes: 2 additions & 2 deletions chain/rosetta-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use config::RosettaRpcConfig;
use near_chain_configs::Genesis;
use near_client::{ClientActor, ViewClientActor};
use near_o11y::WithSpanContextExt;
use near_primitives::borsh::BorshDeserialize;
use near_primitives::{account::AccountContract, borsh::BorshDeserialize};

mod adapters;
mod config;
Expand Down Expand Up @@ -369,7 +369,7 @@ async fn account_balance(
Err(crate::errors::ErrorKind::NotFound(_)) => (
block.header.hash,
block.header.height,
near_primitives::account::Account::new(0, 0, Default::default(), 0).into(),
near_primitives::account::Account::new(0, 0, AccountContract::None, 0).into(),
),
Err(err) => return Err(err.into()),
};
Expand Down
4 changes: 2 additions & 2 deletions core/chain-configs/src/genesis_validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ mod test {

use crate::GenesisRecords;
use near_crypto::{KeyType, PublicKey};
use near_primitives::account::{AccessKey, Account};
use near_primitives::account::{AccessKey, Account, AccountContract};
use near_primitives::types::AccountInfo;

const VALID_ED25519_RISTRETTO_KEY: &str = "ed25519:KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7";

fn create_account() -> Account {
Account::new(100, 10, Default::default(), 0)
Account::new(100, 10, AccountContract::None, 0)
}

#[test]
Expand Down
7 changes: 3 additions & 4 deletions core/chain-configs/src/test_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use std::sync::Arc;

use near_crypto::PublicKey;
use near_primitives::account::{AccessKey, Account};
use near_primitives::account::{AccessKey, Account, AccountContract};
use near_primitives::epoch_manager::{EpochConfig, EpochConfigStore};
use near_primitives::hash::CryptoHash;
use near_primitives::shard_layout::ShardLayout;
use near_primitives::state_record::StateRecord;
use near_primitives::test_utils::{create_test_signer, create_user_test_signer};
Expand Down Expand Up @@ -447,7 +446,7 @@ impl TestGenesisBuilder {
account: Account::new(
user_account.balance,
validator_stake.remove(&user_account.account_id).unwrap_or(0),
CryptoHash::default(),
AccountContract::None,
0,
),
});
Expand All @@ -465,7 +464,7 @@ impl TestGenesisBuilder {
for (account_id, balance) in validator_stake {
records.push(StateRecord::Account {
account_id,
account: Account::new(0, balance, CryptoHash::default(), 0),
account: Account::new(0, balance, AccountContract::None, 0),
});
}

Expand Down
4 changes: 2 additions & 2 deletions core/chain-configs/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use near_crypto::{InMemorySigner, PublicKey};
use near_primitives::account::{AccessKey, Account};
use near_primitives::account::{AccessKey, Account, AccountContract};
use near_primitives::hash::CryptoHash;
use near_primitives::shard_layout::ShardLayout;
use near_primitives::state_record::StateRecord;
Expand Down Expand Up @@ -185,7 +185,7 @@ pub fn add_account_with_key(
) {
records.push(StateRecord::Account {
account_id: account_id.clone(),
account: Account::new(amount, staked, code_hash, 0),
account: Account::new(amount, staked, AccountContract::from_local_code_hash(code_hash), 0),
});
records.push(StateRecord::AccessKey {
account_id,
Expand Down
Loading
Loading