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

Force deploy #4025

Merged
merged 62 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
f77e46e
[force-deploy] add initial codes force deploy command into db exporter
welbon Mar 28, 2024
97f5d0f
add the project of force upgrade
welbon Mar 31, 2024
8ce06a5
[force deploy] Add suiteable binary files of starcoin framework
welbon Apr 1, 2024
6ca6f30
[force-deploy] revert gas schedule
welbon Apr 2, 2024
01c19fa
[force-upgrade] reformat upgrade code
welbon Apr 2, 2024
d7fe44a
[force-deploy] reformat some code for unittest
welbon Apr 3, 2024
73c23cf
[force-deploy] A new txn verify and modification scheme is used, base…
welbon Apr 6, 2024
b4c2c4a
[force-deploy] modify code
welbon Apr 7, 2024
5158faf
[force-deploy] upgrade framework mv file for barnard and proxima
welbon Apr 7, 2024
af2e3f2
fixed for test
welbon Apr 7, 2024
e58d715
for account get from multi chain id
welbon Apr 8, 2024
70b962a
fixed error
welbon Apr 8, 2024
06521d7
[force-upgrade] move the code into openedblock
welbon Apr 9, 2024
99d60c3
[force-deploy] add include_dir and fixed the genesis version of proxi…
welbon Apr 9, 2024
0cc188b
[force-upgrade] change to new process
welbon Apr 10, 2024
27cc5fc
[force-upgrade] change to new process
welbon Apr 10, 2024
2a34ef8
binary file
welbon Apr 10, 2024
3a096a9
[force-upgrade] change to new process
welbon Apr 10, 2024
11927b9
[force-upgrade] add block timestamp
welbon Apr 11, 2024
d7ffd50
[force-upgrade] remove unused code
welbon Apr 11, 2024
a783a45
[force-upgrade] fixed upgrade test error
welbon Apr 11, 2024
5a34cc3
[force-upgrade] fixed the timestamp
welbon Apr 11, 2024
80fa0bc
[force-upgrade] fixed the timestamp
welbon Apr 11, 2024
4203ffc
[force-upgrade] fixed the script for include_dir
welbon Apr 11, 2024
656db9b
[force-upgrade] fixed timestamp
welbon Apr 11, 2024
12dbb19
[force-upgrade] reverted gas scheduler
welbon Apr 11, 2024
1c8ac22
[force-upgrade] reverted gas scheduler
welbon Apr 11, 2024
9cdf159
[force-upgrade] merged from commit "224ee92b878f8a8f4e1628bcd2464f7df…
welbon Apr 11, 2024
21c8608
[force-upgrade] change inappropriate file name
welbon Apr 12, 2024
62fedfb
[force-upgrade] fixed executed for add result to accumulator
welbon Apr 12, 2024
a5e205b
[force-deploy] add some case
welbon Apr 12, 2024
3361d28
[force-upgrade] change for test
welbon Apr 12, 2024
8bbd2a8
[force-upgrade] Change unittest for verify block template
welbon Apr 12, 2024
7913128
[force-upgrade] remove check function
welbon Apr 12, 2024
41678a1
fix compiling errors and warnings
simonjiao Apr 12, 2024
8b6eb1d
fix unused code
nkysg Apr 12, 2024
2c44243
Revert "[force-upgrade] fixed executed for add result to accumulator"
simonjiao Apr 13, 2024
a4aae5b
fix force upgrade txn test case
simonjiao Apr 13, 2024
5729a9c
fix burning tokens test
simonjiao Apr 13, 2024
c823322
add more check for main network when executing extra txn
simonjiao Apr 13, 2024
ed5f6f1
update stdlib version directly
simonjiao Apr 13, 2024
e29bf6d
fix fmt
simonjiao Apr 13, 2024
ddc3949
stdlib framework v11 with move version 6 for test
nkysg Apr 12, 2024
6b57cc2
some updates
simonjiao Apr 13, 2024
c5ac4ee
update force-deploy pkg path
simonjiao Apr 14, 2024
515a7fc
update deploy account for main network
simonjiao Apr 14, 2024
fce9ffb
fix test cases
simonjiao Apr 14, 2024
3268a42
update halley genesis
simonjiao Apr 14, 2024
da99dfe
minor updates
simonjiao Apr 14, 2024
23f9ae2
update halley force upgrade height
simonjiao Apr 14, 2024
99bb637
[force-deploy] set halley upgrade number to 600
welbon Apr 14, 2024
e64ce6a
[force-upgrade] update genesis timestamp for halley test
welbon Apr 14, 2024
65741f2
[force-upgrade]
welbon Apr 14, 2024
34be497
[force-upgrade]
welbon Apr 14, 2024
a76c9ac
[force-upgrade] update genesis
welbon Apr 14, 2024
43fdc72
change force deploy height of test network
simonjiao Apr 15, 2024
bd85cbc
update extra-txn proccessing
simonjiao Apr 15, 2024
2b3464d
fix benchmark
simonjiao Apr 16, 2024
95aa4b7
Merge branch 'master' into force_deploy
simonjiao Apr 16, 2024
d50a508
[force-upgrade] set the barnard upgrade number
welbon Apr 17, 2024
c3c4eb5
[force-upgrade] set the barnard upgrade number to 16082000
welbon Apr 17, 2024
c34f807
update force deploy height for barnard
simonjiao Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
36 changes: 35 additions & 1 deletion Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ members = [
"chain",
"chain/api",
"chain/open-block",
"chain/force-upgrade",
"chain/mock",
"chain/chain-notify",
"chain/service",
Expand Down Expand Up @@ -152,6 +153,7 @@ default-members = [
"chain",
"chain/api",
"chain/open-block",
"chain/force-upgrade",
"chain/mock",
"chain/chain-notify",
"chain/service",
Expand Down Expand Up @@ -442,7 +444,7 @@ starcoin-crypto = { git = "https://github.com/starcoinorg/starcoin-crypto", rev
starcoin-decrypt = { path = "commons/decrypt" }
starcoin-dev = { path = "vm/dev" }
starcoin-executor = { path = "executor" }
starcoin-framework = { git = "https://github.com/starcoinorg/starcoin-framework", rev = "345a3900a0064dc57a9560235bc72c12f03448b1" }
starcoin-framework = { git = "https://github.com/starcoinorg/starcoin-framework", rev = "82270f389e91418321b0dd8785d63ee9d0470505" }
starcoin-genesis = { path = "genesis" }
starcoin-logger = { path = "commons/logger" }
starcoin-metrics = { path = "commons/metrics" }
Expand All @@ -460,6 +462,7 @@ starcoin-network-rpc-api = { path = "network-rpc/api" }
starcoin-node = { path = "node" }
starcoin-node-api = { path = "node/api" }
starcoin-open-block = { path = "chain/open-block" }
starcoin-force-upgrade = { path = "chain/force-upgrade" }
starcoin-resource-viewer = { path = "vm/resource-viewer" }
starcoin-rpc-api = { path = "rpc/api" }
starcoin-rpc-client = { path = "rpc/client" }
Expand Down
3 changes: 3 additions & 0 deletions chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ starcoin-statedb = { workspace = true }
starcoin-time-service = { workspace = true }
starcoin-types = { package = "starcoin-types", workspace = true }
starcoin-vm-types = { workspace = true }
starcoin-vm-runtime = { workspace = true }
starcoin-force-upgrade = { workspace = true }
starcoin-storage = { workspace = true }
thiserror = { workspace = true }
once_cell = { workspace = true }
Expand All @@ -41,6 +43,7 @@ stdlib = { workspace = true }
stest = { workspace = true }
test-helper = { workspace = true }
tokio = { features = ["full"], workspace = true }
starcoin-force-upgrade = { workspace = true }

[features]
default = []
Expand Down
34 changes: 34 additions & 0 deletions chain/force-upgrade/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
name = "starcoin-force-upgrade"
publish = { workspace = true }
version = "1.13.10"
homepage = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }


[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
bcs-ext = { package = "bcs-ext", workspace = true }
starcoin-crypto = { workspace = true }
futures = { workspace = true }
starcoin-logger = { workspace = true }
parking_lot = { workspace = true }
starcoin-accumulator = { workspace = true }
starcoin-chain-api = { workspace = true }
starcoin-state-api = { workspace = true }
starcoin-statedb = { workspace = true }
starcoin-storage = { workspace = true }
starcoin-types = { workspace = true }
starcoin-vm-types = { workspace = true }
starcoin-vm-runtime = { workspace = true }
starcoin-move-compiler = { workspace = true }
include_dir = { workspace = true }

[dev-dependencies]
starcoin-genesis = { workspace = true }
stest = { workspace = true }
Binary file added chain/force-upgrade/package/stdlib.blob
Binary file not shown.
45 changes: 45 additions & 0 deletions chain/force-upgrade/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use anyhow::format_err;

use starcoin_types::{
account::{Account, DEFAULT_MAX_GAS_AMOUNT},
transaction::SignedUserTransaction,
};

use include_dir::{include_dir, Dir};
use starcoin_vm_types::{
account_config::STC_TOKEN_CODE_STR,
genesis_config::ChainId,
transaction::{Package, RawUserTransaction, TransactionPayload},
};

pub const FORCE_UPGRADE_PACKAGE: Dir = include_dir!("package");

pub struct ForceUpgrade;

impl ForceUpgrade {
pub fn force_deploy_txn(
account: Account,
sequence_number: u64,
chain_id: &ChainId,
) -> anyhow::Result<SignedUserTransaction> {
let package_file = "stdlib.blob".to_string();
let package = FORCE_UPGRADE_PACKAGE
nkysg marked this conversation as resolved.
Show resolved Hide resolved
.get_file(package_file.clone())
.map(|file| {
bcs_ext::from_bytes::<Package>(file.contents())
.expect("Decode package should success")
})
.ok_or_else(|| format_err!("Can not find upgrade package {}", package_file))?;

Ok(account.sign_txn(RawUserTransaction::new(
account.address().clone(),
sequence_number,
TransactionPayload::Package(package),
DEFAULT_MAX_GAS_AMOUNT,
1,
3600,
nkysg marked this conversation as resolved.
Show resolved Hide resolved
chain_id.clone(),
STC_TOKEN_CODE_STR.to_string(),
)))
}
}
3 changes: 3 additions & 0 deletions chain/open-block/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ starcoin-state-api = { workspace = true }
starcoin-statedb = { workspace = true }
starcoin-storage = { workspace = true }
starcoin-types = { workspace = true }
starcoin-vm-types = { workspace = true }
starcoin-vm-runtime = { workspace = true }
starcoin-force-upgrade = { workspace = true }

[dev-dependencies]
starcoin-genesis = { workspace = true }
Expand Down
76 changes: 75 additions & 1 deletion chain/open-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use starcoin_accumulator::{node::AccumulatorStoreType, Accumulator, MerkleAccumu
use starcoin_chain_api::ExcludedTxns;
use starcoin_crypto::HashValue;
use starcoin_executor::{execute_block_transactions, execute_transactions, VMMetrics};
use starcoin_force_upgrade::ForceUpgrade;
use starcoin_logger::prelude::*;
use starcoin_state_api::{ChainStateReader, ChainStateWriter};
use starcoin_statedb::ChainStateDB;
Expand All @@ -23,6 +24,13 @@ use starcoin_types::{
},
U256,
};
use starcoin_vm_runtime::force_upgrade_data_cache::{
get_force_upgrade_account, get_force_upgrade_block_number,
};
use starcoin_vm_types::access_path::AccessPath;
use starcoin_vm_types::account_config::{genesis_address, ModuleUpgradeStrategy};
use starcoin_vm_types::move_resource::MoveResource;
use starcoin_vm_types::state_view::StateReaderExt;
use std::{convert::TryInto, sync::Arc};

pub struct OpenedBlock {
Expand All @@ -40,6 +48,7 @@ pub struct OpenedBlock {
difficulty: U256,
strategy: ConsensusStrategy,
vm_metrics: Option<VMMetrics>,
extra_txn: Option<SignedUserTransaction>,
}

impl OpenedBlock {
Expand Down Expand Up @@ -77,11 +86,23 @@ impl OpenedBlock {
chain_id,
previous_header.gas_used(),
);

let extra_txn = if block_meta.number() == get_force_upgrade_block_number(&chain_id) {
let account = get_force_upgrade_account(&chain_id)?;
let seqence_number = chain_state.get_sequence_number(account.address().clone())?;
Some(ForceUpgrade::force_deploy_txn(
account,
seqence_number,
&chain_id,
)?)
} else {
None
};

let mut opened_block = Self {
previous_block_info: block_info,
block_meta,
gas_limit: block_gas_limit,

state: chain_state,
txn_accumulator,
gas_used: 0,
Expand All @@ -91,7 +112,9 @@ impl OpenedBlock {
difficulty,
strategy,
vm_metrics,
extra_txn,
};

opened_block.initialize()?;
Ok(opened_block)
}
Expand Down Expand Up @@ -131,6 +154,14 @@ impl OpenedBlock {
&self.state
}

pub fn state_writer(&self) -> &impl ChainStateWriter {
nkysg marked this conversation as resolved.
Show resolved Hide resolved
&self.state
}

pub fn chain_id(&self) -> ChainId {
self.chain_id
}

/// Try to add `user_txns` into this block.
/// Return any txns not included, either txn is discarded, or block gas limit is reached.
/// If error occurs during the processing, the `open_block` should be dropped,
Expand Down Expand Up @@ -198,6 +229,7 @@ impl OpenedBlock {
}
};
}

Ok(ExcludedTxns {
discarded_txns: discard_txns,
untouched_txns: untouched_user_txns,
Expand Down Expand Up @@ -271,6 +303,8 @@ impl OpenedBlock {

/// Construct a block template for mining.
pub fn finalize(self) -> Result<BlockTemplate> {
self.execute_extra_txn()?;

let accumulator_root = self.txn_accumulator.root_hash();
let state_root = self.state.state_root();
let uncles = if !self.uncles.is_empty() {
Expand All @@ -294,7 +328,47 @@ impl OpenedBlock {
);
Ok(block_template)
}

/// The logic for handling the forced upgrade will be processed.
/// First, set the account policy in `0x1::PackageTxnManager` to 100,
/// Second, after the contract deployment is successful, revert it back.
fn execute_extra_txn(&self) -> Result<()> {
if self.extra_txn.is_none() {
return Ok(());
}

let gas_left = self.gas_limit.checked_sub(self.gas_used).ok_or_else(|| {
nkysg marked this conversation as resolved.
Show resolved Hide resolved
format_err!(
"block gas_used {} exceed block gas_limit:{}",
self.gas_used,
self.gas_limit
)
})?;

let strategy_path = AccessPath::resource_access_path(
genesis_address(),
ModuleUpgradeStrategy::struct_tag(),
);

// Set strategy to 100
self.state.set(&strategy_path, vec![100])?;

execute_block_transactions(
&self.state,
nkysg marked this conversation as resolved.
Show resolved Hide resolved
vec![Transaction::UserTransaction(
self.extra_txn.as_ref().unwrap().clone(),
)],
gas_left,
self.vm_metrics.clone(),
)?;

// Set strategy to 1
self.state.set(&strategy_path, vec![1])?;

Ok(())
}
}

pub struct AddressFilter;
//static BLACKLIST: [&str; 0] = [];
impl AddressFilter {
Expand Down
Loading
Loading