From 24177fac262fd403cc198f107ac21ffb67b5d85e Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Mon, 4 Nov 2024 18:12:14 +0700 Subject: [PATCH 01/40] feat: hardcoded identity transfers in strategy tests --- .../tests/strategy_tests/main.rs | 7 +- .../tests/strategy_tests/strategy.rs | 14 ++- .../tests/strategy_tests/voting_tests.rs | 90 +++++++++++-------- packages/strategy-tests/src/lib.rs | 71 ++++++++++----- packages/strategy-tests/src/operations.rs | 19 +++- packages/strategy-tests/src/transitions.rs | 2 +- 6 files changed, 137 insertions(+), 66 deletions(-) diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index 2312241cc64..f2122d627ef 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -2602,7 +2602,10 @@ mod tests { &simple_signer, &mut rng, platform_version, - ); + ) + .iter() + .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .collect(); let strategy = NetworkStrategy { strategy: Strategy { @@ -3910,7 +3913,7 @@ mod tests { strategy: Strategy { start_contracts: vec![], operations: vec![Operation { - op_type: OperationType::IdentityTransfer, + op_type: OperationType::IdentityTransfer(None), frequency: Frequency { times_per_block_range: 1..3, chance_per_block: None, diff --git a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs index 667b8468688..4d1a7ccb624 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs @@ -41,7 +41,7 @@ use drive_abci::rpc::core::MockCoreRPCLike; use rand::prelude::{IteratorRandom, SliceRandom, StdRng}; use rand::Rng; use strategy_tests::Strategy; -use strategy_tests::transitions::{create_state_transitions_for_identities, create_state_transitions_for_identities_and_proofs, instant_asset_lock_proof_fixture, instant_asset_lock_proof_fixture_with_dynamic_range}; +use strategy_tests::transitions::{create_state_transitions_for_identities, create_state_transitions_for_identities_and_proofs, instant_asset_lock_proof_fixture_with_dynamic_range}; use std::borrow::Cow; use std::collections::{BTreeMap, HashMap, HashSet}; use std::ops::RangeInclusive; @@ -405,7 +405,15 @@ impl NetworkStrategy { state_transitions.append(&mut new_transitions); } if !self.strategy.start_identities.hard_coded.is_empty() { - state_transitions.extend(self.strategy.start_identities.hard_coded.clone()); + state_transitions.extend( + self.strategy.start_identities.hard_coded.iter().filter_map( + |(identity, transition)| { + transition.as_ref().map(|create_transition| { + (identity.clone(), create_transition.clone()) + }) + }, + ), + ); } } let frequency = &self.strategy.identity_inserts.frequency; @@ -1196,7 +1204,7 @@ impl NetworkStrategy { operations.push(state_transition); } } - OperationType::IdentityTransfer if current_identities.len() > 1 => { + OperationType::IdentityTransfer(_) if current_identities.len() > 1 => { let identities_clone = current_identities.clone(); // Sender is the first in the list, which should be loaded_identity diff --git a/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs index e14f8d7b1b0..2264a4cd5fb 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs @@ -79,13 +79,17 @@ mod tests { simple_signer.add_keys(keys1); - let start_identities = create_state_transitions_for_identities( - vec![identity1], - &(dash_to_duffs!(1)..=dash_to_duffs!(1)), - &simple_signer, - &mut rng, - platform_version, - ); + let start_identities: Vec<(Identity, Option)> = + create_state_transitions_for_identities( + vec![identity1], + &(dash_to_duffs!(1)..=dash_to_duffs!(1)), + &simple_signer, + &mut rng, + platform_version, + ) + .iter() + .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .collect(); let dpns_contract = platform .drive @@ -363,13 +367,17 @@ mod tests { simple_signer.add_keys(keys2); - let start_identities = create_state_transitions_for_identities( - vec![identity1, identity2], - &(dash_to_duffs!(1)..=dash_to_duffs!(1)), - &simple_signer, - &mut rng, - platform_version, - ); + let start_identities: Vec<(Identity, Option)> = + create_state_transitions_for_identities( + vec![identity1, identity2], + &(dash_to_duffs!(1)..=dash_to_duffs!(1)), + &simple_signer, + &mut rng, + platform_version, + ) + .iter() + .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .collect(); let dpns_contract = platform .drive @@ -635,13 +643,17 @@ mod tests { simple_signer.add_keys(keys2); - let start_identities = create_state_transitions_for_identities( - vec![identity1, identity2], - &(dash_to_duffs!(1)..=dash_to_duffs!(1)), - &simple_signer, - &mut rng, - platform_version, - ); + let start_identities: Vec<(Identity, Option)> = + create_state_transitions_for_identities( + vec![identity1, identity2], + &(dash_to_duffs!(1)..=dash_to_duffs!(1)), + &simple_signer, + &mut rng, + platform_version, + ) + .iter() + .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .collect(); let dpns_contract = platform .drive @@ -988,13 +1000,17 @@ mod tests { simple_signer.add_keys(keys2); - let start_identities = create_state_transitions_for_identities( - vec![identity1, identity2], - &(dash_to_duffs!(1)..=dash_to_duffs!(1)), - &simple_signer, - &mut rng, - platform_version, - ); + let start_identities: Vec<(Identity, Option)> = + create_state_transitions_for_identities( + vec![identity1, identity2], + &(dash_to_duffs!(1)..=dash_to_duffs!(1)), + &simple_signer, + &mut rng, + platform_version, + ) + .iter() + .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .collect(); let dpns_contract = platform .drive @@ -1353,13 +1369,17 @@ mod tests { simple_signer.add_keys(keys2); - let start_identities = create_state_transitions_for_identities( - vec![identity1, identity2], - &(dash_to_duffs!(1)..=dash_to_duffs!(1)), - &simple_signer, - &mut rng, - platform_version, - ); + let start_identities: Vec<(Identity, Option)> = + create_state_transitions_for_identities( + vec![identity1, identity2], + &(dash_to_duffs!(1)..=dash_to_duffs!(1)), + &simple_signer, + &mut rng, + platform_version, + ) + .iter() + .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .collect(); let dpns_contract = platform .drive diff --git a/packages/strategy-tests/src/lib.rs b/packages/strategy-tests/src/lib.rs index 61395d99f2a..65e8a51f851 100644 --- a/packages/strategy-tests/src/lib.rs +++ b/packages/strategy-tests/src/lib.rs @@ -44,6 +44,7 @@ use platform_version::TryFromPlatformVersioned; use rand::prelude::StdRng; use rand::seq::{IteratorRandom, SliceRandom}; use rand::Rng; +use transitions::create_identity_credit_transfer_transition; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::ops::RangeInclusive; use bincode::{Decode, Encode}; @@ -146,7 +147,7 @@ pub struct StartIdentities { pub keys_per_identity: u8, pub starting_balances: u64, // starting balance in duffs pub extra_keys: KeyMaps, - pub hard_coded: Vec<(Identity, StateTransition)>, + pub hard_coded: Vec<(Identity, Option)>, } /// Identities to register on the first block of the strategy @@ -1287,38 +1288,66 @@ impl Strategy { } // Generate state transition for identity transfer operation - OperationType::IdentityTransfer if current_identities.len() > 1 => { + OperationType::IdentityTransfer(identity_transfer_info) => { for _ in 0..count { - let identities_count = current_identities.len(); - if identities_count == 0 { - break; - } + if let Some(transfer_info) = identity_transfer_info { + let sender = self + .start_identities + .hard_coded + .iter() + .find(|(identity, _)| identity.id() == transfer_info.from) + .expect( + "Expected to find sender identity in hardcoded start identities", + ); + let recipient = self + .start_identities + .hard_coded + .iter() + .find(|(identity, _)| identity.id() == transfer_info.to) + .expect( + "Expected to find recipient identity in hardcoded start identities", + ); + + let state_transition = create_identity_credit_transfer_transition( + &sender.0, + &recipient.0, + identity_nonce_counter, + signer, // Does this mean the loaded identity must be the sender since we're signing with it? + transfer_info.amount, + ); + operations.push(state_transition); + } else if current_identities.len() > 1 { + let identities_count = current_identities.len(); + if identities_count == 0 { + break; + } - // Select a random identity from the current_identities for the sender - let random_index_sender = rng.gen_range(0..identities_count); + // Select a random identity from the current_identities for the sender + let random_index_sender = rng.gen_range(0..identities_count); - // Clone current_identities to a Vec for manipulation - let mut unused_identities: Vec<_> = - current_identities.iter().cloned().collect(); - unused_identities.remove(random_index_sender); // Remove the sender - let unused_identities_count = unused_identities.len(); + // Clone current_identities to a Vec for manipulation + let mut unused_identities: Vec<_> = + current_identities.iter().cloned().collect(); + unused_identities.remove(random_index_sender); // Remove the sender + let unused_identities_count = unused_identities.len(); - // Select a random identity from the remaining ones for the recipient - let random_index_recipient = rng.gen_range(0..unused_identities_count); - let recipient = &unused_identities[random_index_recipient]; + // Select a random identity from the remaining ones for the recipient + let random_index_recipient = + rng.gen_range(0..unused_identities_count); + let recipient = &unused_identities[random_index_recipient]; - // Use the sender index on the original slice - let sender = &mut current_identities[random_index_sender]; + // Use the sender index on the original slice + let sender = &mut current_identities[random_index_sender]; - let state_transition = - crate::transitions::create_identity_credit_transfer_transition( + let state_transition = create_identity_credit_transfer_transition( sender, recipient, identity_nonce_counter, signer, 300000, ); - operations.push(state_transition); + operations.push(state_transition); + } } } diff --git a/packages/strategy-tests/src/operations.rs b/packages/strategy-tests/src/operations.rs index 675e9968433..d35fc9f5036 100644 --- a/packages/strategy-tests/src/operations.rs +++ b/packages/strategy-tests/src/operations.rs @@ -497,6 +497,13 @@ impl VoteAction { pub type AmountRange = RangeInclusive; +#[derive(Clone, Debug, PartialEq, Encode, Decode)] +pub struct IdentityTransferInfo { + pub from: Identifier, + pub to: Identifier, + pub amount: Credits, +} + #[derive(Clone, Debug, PartialEq)] pub enum OperationType { Document(DocumentOp), @@ -505,7 +512,7 @@ pub enum OperationType { IdentityWithdrawal(AmountRange), ContractCreate(RandomDocumentTypeParameters, DocumentTypeCount), ContractUpdate(DataContractUpdateOp), - IdentityTransfer, + IdentityTransfer(Option), ResourceVote(ResourceVoteOp), } @@ -517,7 +524,7 @@ enum OperationTypeInSerializationFormat { IdentityWithdrawal(AmountRange), ContractCreate(RandomDocumentTypeParameters, DocumentTypeCount), ContractUpdate(Vec), - IdentityTransfer, + IdentityTransfer(Option), ResourceVote(ResourceVoteOpSerializable), } @@ -563,7 +570,9 @@ impl PlatformSerializableWithPlatformVersion for OperationType { contract_op_in_serialization_format, ) } - OperationType::IdentityTransfer => OperationTypeInSerializationFormat::IdentityTransfer, + OperationType::IdentityTransfer(identity_transfer_info) => { + OperationTypeInSerializationFormat::IdentityTransfer(identity_transfer_info) + } OperationType::ResourceVote(resource_vote_op) => { let vote_op_in_serialization_format = resource_vote_op.try_into_platform_versioned(platform_version)?; @@ -626,7 +635,9 @@ impl PlatformDeserializableWithPotentialValidationFromVersionedStructure for Ope )?; OperationType::ContractUpdate(update_op) } - OperationTypeInSerializationFormat::IdentityTransfer => OperationType::IdentityTransfer, + OperationTypeInSerializationFormat::IdentityTransfer(identity_transfer_info) => { + OperationType::IdentityTransfer(identity_transfer_info) + } OperationTypeInSerializationFormat::ResourceVote(resource_vote_op) => { let vote_op = resource_vote_op.try_into_platform_versioned(platform_version)?; OperationType::ResourceVote(vote_op) diff --git a/packages/strategy-tests/src/transitions.rs b/packages/strategy-tests/src/transitions.rs index 85d03eb333d..c77b51e2903 100644 --- a/packages/strategy-tests/src/transitions.rs +++ b/packages/strategy-tests/src/transitions.rs @@ -802,7 +802,7 @@ pub fn create_identity_withdrawal_transition_with_output_address( /// - If the sender's identity does not have a suitable authentication key available for signing. /// - If there's an error during the signing process. pub fn create_identity_credit_transfer_transition( - identity: &mut Identity, + identity: &Identity, recipient: &Identity, identity_nonce_counter: &mut BTreeMap, signer: &mut SimpleSigner, From dacc6dbd04b6c4f9593c7c8ab128ac1f5a094e4f Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 4 Nov 2024 18:30:19 +0700 Subject: [PATCH 02/40] fix(drive): uncommitted state if db transaction fails (#2305) --- .../src/abci/handler/finalize_block.rs | 26 +++++++++- .../rs-drive-abci/src/abci/handler/info.rs | 52 ++++++++++++++++--- .../src/abci/handler/prepare_proposal.rs | 43 +++++++++++++++ .../src/abci/handler/process_proposal.rs | 43 +++++++++++++++ 4 files changed, 157 insertions(+), 7 deletions(-) diff --git a/packages/rs-drive-abci/src/abci/handler/finalize_block.rs b/packages/rs-drive-abci/src/abci/handler/finalize_block.rs index 9653391c7d5..852f85cc6b8 100644 --- a/packages/rs-drive-abci/src/abci/handler/finalize_block.rs +++ b/packages/rs-drive-abci/src/abci/handler/finalize_block.rs @@ -5,6 +5,7 @@ use crate::execution::types::block_execution_context::v0::BlockExecutionContextV use crate::platform_types::cleaned_abci_messages::finalized_block_cleaned_request::v0::FinalizeBlockCleanedRequest; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::rpc::core::CoreRPCLike; +use dpp::dashcore::Network; use std::sync::atomic::Ordering; use tenderdash_abci::proto::abci as proto; @@ -66,7 +67,30 @@ where )); } - app.commit_transaction(platform_version)?; + let result = app.commit_transaction(platform_version); + + // We had a sequence of errors on the mainnet started since block 32326. + // We got RocksDB's "transaction is busy" error because of a bug (https://github.com/dashpay/platform/pull/2309). + // Due to another bug in Tenderdash (https://github.com/dashpay/tenderdash/pull/966), + // validators just proceeded to the next block partially committing the state and updating the cache. + // Full nodes are stuck and proceeded after re-sync. + // For the mainnet chain, we enable these fixes at the block when we consider the state is consistent. + let config = &app.platform().config; + + if app.platform().config.network == Network::Dash + && config.abci.chain_id == "evo1" + && block_height < 33000 + { + // Old behavior on mainnet below block 33000 + result?; + } else { + // In case if transaction commit failed we still have caches in memory that + // corresponds to the data that we weren't able to commit. + // The simplified solution is to restart the Drive, so all caches + // will be restored from the disk and try to process this block again. + // TODO: We need a better handling of the transaction is busy error with retry logic. + result.expect("commit transaction"); + } app.platform() .committed_block_height_guard diff --git a/packages/rs-drive-abci/src/abci/handler/info.rs b/packages/rs-drive-abci/src/abci/handler/info.rs index dbb85018913..9ac9d316267 100644 --- a/packages/rs-drive-abci/src/abci/handler/info.rs +++ b/packages/rs-drive-abci/src/abci/handler/info.rs @@ -3,6 +3,7 @@ use crate::abci::AbciError; use crate::error::Error; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::rpc::core::CoreRPCLike; +use dpp::dashcore::Network; use dpp::version::DESIRED_PLATFORM_VERSION; use tenderdash_abci::proto::abci as proto; @@ -21,19 +22,58 @@ where let platform_state = app.platform().state.load(); - let state_app_hash = platform_state + let last_block_height = platform_state.last_committed_block_height() as i64; + + // Verify that Platform State corresponds to Drive commited state + let platform_state_app_hash = platform_state .last_committed_block_app_hash() - .map(|app_hash| app_hash.to_vec()) .unwrap_or_default(); + let grove_version = &platform_state + .current_platform_version()? + .drive + .grove_version; + + let drive_storage_root_hash = app + .platform() + .drive + .grove + .root_hash(None, grove_version) + .unwrap()?; + + // We had a sequence of errors on the mainnet started since block 32326. + // We got RocksDB's "transaction is busy" error because of a bug (https://github.com/dashpay/platform/pull/2309). + // Due to another bug in Tenderdash (https://github.com/dashpay/tenderdash/pull/966), + // validators just proceeded to the next block partially committing the state and updating the cache. + // Full nodes are stuck and proceeded after re-sync. + // For the mainnet chain, we enable these fixes at the block when we consider the state is consistent. + let config = &app.platform().config; + + #[allow(clippy::collapsible_if)] + if !(config.network == Network::Dash + && config.abci.chain_id == "evo1" + && last_block_height < 33000) + { + // App hash in memory must be equal to app hash on disk + if drive_storage_root_hash != platform_state_app_hash { + // We panic because we can't recover from this situation. + // Better to restart the Drive, so we might self-heal the node + // reloading state form the disk + panic!( + "drive and platform state app hash mismatch: drive_storage_root_hash: {:?}, platform_state_app_hash: {:?}", + drive_storage_root_hash, platform_state_app_hash + ); + } + } + let desired_protocol_version = DESIRED_PLATFORM_VERSION.protocol_version; let response = proto::ResponseInfo { data: "".to_string(), app_version: desired_protocol_version as u64, - last_block_height: platform_state.last_committed_block_height() as i64, + last_block_height, version: env!("CARGO_PKG_VERSION").to_string(), - last_block_app_hash: state_app_hash.clone(), + last_block_app_hash: platform_state_app_hash.to_vec(), }; tracing::debug!( @@ -41,8 +81,8 @@ where software_version = env!("CARGO_PKG_VERSION"), block_version = request.block_version, p2p_version = request.p2p_version, - app_hash = hex::encode(state_app_hash), - height = platform_state.last_committed_block_height(), + app_hash = hex::encode(platform_state_app_hash), + last_block_height, "Handshake with consensus engine", ); diff --git a/packages/rs-drive-abci/src/abci/handler/prepare_proposal.rs b/packages/rs-drive-abci/src/abci/handler/prepare_proposal.rs index 18252d0d451..61f58a01960 100644 --- a/packages/rs-drive-abci/src/abci/handler/prepare_proposal.rs +++ b/packages/rs-drive-abci/src/abci/handler/prepare_proposal.rs @@ -11,6 +11,7 @@ use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::state_transitions_processing_result::StateTransitionExecutionResult; use crate::rpc::core::CoreRPCLike; use dpp::dashcore::hashes::Hash; +use dpp::dashcore::Network; use dpp::version::TryIntoPlatformVersioned; use drive::grovedb_storage::Error::RocksDBError; use tenderdash_abci::proto::abci as proto; @@ -35,6 +36,48 @@ where let platform_state = app.platform().state.load(); + // Verify that Platform State corresponds to Drive commited state + let platform_state_app_hash = platform_state + .last_committed_block_app_hash() + .unwrap_or_default(); + + let grove_version = &platform_state + .current_platform_version()? + .drive + .grove_version; + + let drive_storage_root_hash = app + .platform() + .drive + .grove + .root_hash(None, grove_version) + .unwrap()?; + + // We had a sequence of errors on the mainnet started since block 32326. + // We got RocksDB's "transaction is busy" error because of a bug (https://github.com/dashpay/platform/pull/2309). + // Due to another bug in Tenderdash (https://github.com/dashpay/tenderdash/pull/966), + // validators just proceeded to the next block partially committing the state and updating the cache. + // Full nodes are stuck and proceeded after re-sync. + // For the mainnet chain, we enable these fixes at the block when we consider the state is consistent. + let config = &app.platform().config; + + #[allow(clippy::collapsible_if)] + if !(config.network == Network::Dash + && config.abci.chain_id == "evo1" + && request.height < 33000) + { + // App hash in memory must be equal to app hash on disk + if drive_storage_root_hash != platform_state_app_hash { + // We panic because we can't recover from this situation. + // Better to restart the Drive, so we might self-heal the node + // reloading state form the disk + panic!( + "drive and platform state app hash mismatch: drive_storage_root_hash: {:?}, platform_state_app_hash: {:?}", + drive_storage_root_hash, platform_state_app_hash + ); + } + } + let last_committed_core_height = platform_state.last_committed_core_height(); let starting_platform_version = platform_state.current_platform_version()?; diff --git a/packages/rs-drive-abci/src/abci/handler/process_proposal.rs b/packages/rs-drive-abci/src/abci/handler/process_proposal.rs index 5bf547e14a7..d40567d3db2 100644 --- a/packages/rs-drive-abci/src/abci/handler/process_proposal.rs +++ b/packages/rs-drive-abci/src/abci/handler/process_proposal.rs @@ -12,6 +12,7 @@ use crate::platform_types::block_execution_outcome; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::state_transitions_processing_result::StateTransitionExecutionResult; use crate::rpc::core::CoreRPCLike; +use dpp::dashcore::Network; use dpp::version::TryIntoPlatformVersioned; use drive::grovedb_storage::Error::RocksDBError; use tenderdash_abci::proto::abci as proto; @@ -179,6 +180,48 @@ where let platform_state = app.platform().state.load(); + // Verify that Platform State corresponds to Drive commited state + let platform_state_app_hash = platform_state + .last_committed_block_app_hash() + .unwrap_or_default(); + + let grove_version = &platform_state + .current_platform_version()? + .drive + .grove_version; + + let drive_storage_root_hash = app + .platform() + .drive + .grove + .root_hash(None, grove_version) + .unwrap()?; + + // We had a sequence of errors on the mainnet started since block 32326. + // We got RocksDB's "transaction is busy" error because of a bug (https://github.com/dashpay/platform/pull/2309). + // Due to another bug in Tenderdash (https://github.com/dashpay/tenderdash/pull/966), + // validators just proceeded to the next block partially committing the state and updating the cache. + // Full nodes are stuck and proceeded after re-sync. + // For the mainnet chain, we enable these fixes at the block when we consider the state is consistent. + let config = &app.platform().config; + + #[allow(clippy::collapsible_if)] + if !(app.platform().config.network == Network::Dash + && config.abci.chain_id == "evo1" + && request.height < 33000) + { + // App hash in memory must be equal to app hash on disk + if drive_storage_root_hash != platform_state_app_hash { + // We panic because we can't recover from this situation. + // Better to restart the Drive, so we might self-heal the node + // reloading state form the disk + panic!( + "drive and platform state app hash mismatch: drive_storage_root_hash: {:?}, platform_state_app_hash: {:?}", + drive_storage_root_hash, platform_state_app_hash + ); + } + } + let starting_platform_version = platform_state.current_platform_version()?; // Running the proposal executes all the state transitions for the block From 306b86cb35fce29bec2c94a660c3923bf13bedd6 Mon Sep 17 00:00:00 2001 From: QuantumExplorer Date: Mon, 4 Nov 2024 12:31:37 +0100 Subject: [PATCH 03/40] fix(drive): apply batch is not using transaction in `remove_all_votes_given_by_identities` (#2309) Co-authored-by: Ivan Shumkov --- .../mod.rs | 3 +++ .../v0/mod.rs | 5 ++++ .../voting/run_dao_platform_events/v0/mod.rs | 1 + .../state_transitions/masternode_vote/mod.rs | 1 + .../mod.rs | 8 +++++++ .../v0/mod.rs | 24 +++++++++++++++++-- 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/mod.rs index 8328eb0fc1c..ffd97c42929 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/mod.rs @@ -3,6 +3,7 @@ use crate::error::Error; use crate::platform_types::platform::Platform; use crate::platform_types::platform_state::PlatformState; use crate::rpc::core::CoreRPCLike; +use dpp::block::block_info::BlockInfo; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; @@ -14,6 +15,7 @@ where /// Removes the votes for removed masternodes pub(in crate::execution) fn remove_votes_for_removed_masternodes( &self, + block_info: &BlockInfo, last_committed_platform_state: &PlatformState, block_platform_state: &PlatformState, transaction: TransactionArg, @@ -26,6 +28,7 @@ where .remove_votes_for_removed_masternodes { 0 => self.remove_votes_for_removed_masternodes_v0( + block_info, last_committed_platform_state, block_platform_state, transaction, diff --git a/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/v0/mod.rs index b0081570c75..04931a3928e 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/v0/mod.rs @@ -3,6 +3,7 @@ use crate::platform_types::platform::Platform; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; use crate::rpc::core::CoreRPCLike; +use dpp::block::block_info::BlockInfo; use dpp::dashcore::hashes::Hash; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; @@ -14,6 +15,7 @@ where /// Removes the votes for removed masternodes pub(super) fn remove_votes_for_removed_masternodes_v0( &self, + block_info: &BlockInfo, last_committed_platform_state: &PlatformState, block_platform_state: &PlatformState, transaction: TransactionArg, @@ -29,6 +31,9 @@ where .iter() .map(|pro_tx_hash| pro_tx_hash.as_byte_array().to_vec()) .collect(), + block_info.height, + self.config.network, + self.config.abci.chain_id.as_str(), transaction, platform_version, )?; diff --git a/packages/rs-drive-abci/src/execution/platform_events/voting/run_dao_platform_events/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/voting/run_dao_platform_events/v0/mod.rs index 2ea9357af14..57fbe635b22 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/voting/run_dao_platform_events/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/voting/run_dao_platform_events/v0/mod.rs @@ -21,6 +21,7 @@ where // Remove any votes that self.remove_votes_for_removed_masternodes( + block_info, last_committed_platform_state, block_platform_state, transaction, diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/mod.rs index fe7d8095b87..9d0394c4420 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/mod.rs @@ -11287,6 +11287,7 @@ mod tests { platform .remove_votes_for_removed_masternodes( + &BlockInfo::default(), &platform_state_before_masternode_identity_removals, &block_platform_state, Some(&transaction), diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/mod.rs index 0f5e0d96040..f93d92a424d 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/mod.rs @@ -5,6 +5,8 @@ use crate::drive::Drive; use crate::error::drive::DriveError; use crate::error::Error; +use dpp::dashcore::Network; +use dpp::prelude::BlockHeight; use dpp::version::PlatformVersion; use grovedb::TransactionArg; @@ -14,6 +16,9 @@ impl Drive { pub fn remove_all_votes_given_by_identities( &self, identity_ids_as_byte_arrays: Vec>, + block_height: BlockHeight, + network: Network, + chain_id: &str, transaction: TransactionArg, platform_version: &PlatformVersion, ) -> Result<(), Error> { @@ -26,6 +31,9 @@ impl Drive { { 0 => self.remove_all_votes_given_by_identities_v0( identity_ids_as_byte_arrays, + block_height, + network, + chain_id, transaction, platform_version, ), diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs index 3c36b0ec647..81b3d0fab7b 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs @@ -11,7 +11,8 @@ use crate::drive::votes::paths::{ use crate::drive::votes::storage_form::contested_document_resource_reference_storage_form::ContestedDocumentResourceVoteReferenceStorageForm; use crate::query::QueryItem; use crate::util::grove_operations::BatchDeleteApplyType; -use dpp::prelude::Identifier; +use dpp::dashcore::Network; +use dpp::prelude::{BlockHeight, Identifier}; use dpp::version::PlatformVersion; use grovedb::query_result_type::QueryResultType::QueryPathKeyElementTrioResultType; use grovedb::{PathQuery, Query, SizedQuery, TransactionArg}; @@ -22,6 +23,9 @@ impl Drive { pub(super) fn remove_all_votes_given_by_identities_v0( &self, identity_ids_as_byte_arrays: Vec>, + block_height: BlockHeight, + network: Network, + chain_id: &str, transaction: TransactionArg, platform_version: &PlatformVersion, ) -> Result<(), Error> { @@ -112,9 +116,25 @@ impl Drive { } if !deletion_batch.is_empty() { + // We had a sequence of errors on the mainnet started since block 32326. + // We got RocksDB's "transaction is busy" error because of a bug (https://github.com/dashpay/platform/pull/2309). + // Due to another bug in Tenderdash (https://github.com/dashpay/tenderdash/pull/966), + // validators just proceeded to the next block partially committing the state + // and updating the cache (https://github.com/dashpay/platform/pull/2305). + // Full nodes are stuck and proceeded after re-sync. + // For the mainnet chain, we enable this fix at the block when we consider the state is consistent. + let transaction = + if network == Network::Dash && chain_id == "evo1" && block_height < 33000 { + // Old behaviour on mainnet + None + } else { + // We should use transaction + transaction + }; + self.apply_batch_low_level_drive_operations( None, - None, + transaction, deletion_batch, &mut vec![], &platform_version.drive, From 99fe5fa402ddcae329795bb29eaf73fd5044b4f2 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Mon, 4 Nov 2024 23:16:36 +0700 Subject: [PATCH 04/40] add comment --- packages/strategy-tests/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/strategy-tests/src/lib.rs b/packages/strategy-tests/src/lib.rs index 65e8a51f851..c2d81ea9905 100644 --- a/packages/strategy-tests/src/lib.rs +++ b/packages/strategy-tests/src/lib.rs @@ -1312,7 +1312,7 @@ impl Strategy { &sender.0, &recipient.0, identity_nonce_counter, - signer, // Does this mean the loaded identity must be the sender since we're signing with it? + signer, // This means the TUI loaded identity must always be the sender since we're always signing with it for now transfer_info.amount, ); operations.push(state_transition); From 0d3e091a5591fde03dbfd8e501864b5ffa2e3602 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Tue, 5 Nov 2024 13:07:49 +0700 Subject: [PATCH 05/40] comment --- packages/rs-drive-abci/tests/strategy_tests/strategy.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs index 4d1a7ccb624..bf3235ea788 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs @@ -404,6 +404,8 @@ impl NetworkStrategy { ); state_transitions.append(&mut new_transitions); } + // Extend the state transitions with the strategy's hard coded start identities + // Filtering out the ones that have no create transition if !self.strategy.start_identities.hard_coded.is_empty() { state_transitions.extend( self.strategy.start_identities.hard_coded.iter().filter_map( From e4215145ad7889300810472c5a91f15ae987c1eb Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Tue, 5 Nov 2024 13:16:38 +0700 Subject: [PATCH 06/40] use into_iter instead of iter --- .../tests/strategy_tests/main.rs | 4 ++-- .../tests/strategy_tests/voting_tests.rs | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index f2122d627ef..03bb92bc1ad 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -2603,8 +2603,8 @@ mod tests { &mut rng, platform_version, ) - .iter() - .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .into_iter() + .map(|(identity, transition)| (identity, Some(transition))) .collect(); let strategy = NetworkStrategy { diff --git a/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs index 2264a4cd5fb..83834520c0c 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs @@ -87,8 +87,8 @@ mod tests { &mut rng, platform_version, ) - .iter() - .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .into_iter() + .map(|(identity, transition)| (identity, Some(transition))) .collect(); let dpns_contract = platform @@ -375,8 +375,8 @@ mod tests { &mut rng, platform_version, ) - .iter() - .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .into_iter() + .map(|(identity, transition)| (identity, Some(transition))) .collect(); let dpns_contract = platform @@ -651,8 +651,8 @@ mod tests { &mut rng, platform_version, ) - .iter() - .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .into_iter() + .map(|(identity, transition)| (identity, Some(transition))) .collect(); let dpns_contract = platform @@ -1008,8 +1008,8 @@ mod tests { &mut rng, platform_version, ) - .iter() - .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .into_iter() + .map(|(identity, transition)| (identity, Some(transition))) .collect(); let dpns_contract = platform @@ -1377,8 +1377,8 @@ mod tests { &mut rng, platform_version, ) - .iter() - .map(|(identity, transition)| (identity.clone(), Some(transition.clone()))) + .into_iter() + .map(|(identity, transition)| (identity, Some(transition))) .collect(); let dpns_contract = platform From 3d941ec5ab7f947e53d41c68eb5758ff2e0bd074 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Tue, 5 Nov 2024 13:31:07 +0700 Subject: [PATCH 07/40] use current identities instead of hardcoded start identities --- packages/strategy-tests/src/lib.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/strategy-tests/src/lib.rs b/packages/strategy-tests/src/lib.rs index c2d81ea9905..efdb702a482 100644 --- a/packages/strategy-tests/src/lib.rs +++ b/packages/strategy-tests/src/lib.rs @@ -1290,33 +1290,32 @@ impl Strategy { // Generate state transition for identity transfer operation OperationType::IdentityTransfer(identity_transfer_info) => { for _ in 0..count { + // Handle the case where specific sender, recipient, and amount are provided if let Some(transfer_info) = identity_transfer_info { - let sender = self - .start_identities - .hard_coded + let sender = current_identities .iter() - .find(|(identity, _)| identity.id() == transfer_info.from) + .find(|identity| identity.id() == transfer_info.from) .expect( "Expected to find sender identity in hardcoded start identities", ); - let recipient = self - .start_identities - .hard_coded + let recipient = current_identities .iter() - .find(|(identity, _)| identity.id() == transfer_info.to) + .find(|identity| identity.id() == transfer_info.to) .expect( "Expected to find recipient identity in hardcoded start identities", ); let state_transition = create_identity_credit_transfer_transition( - &sender.0, - &recipient.0, + &sender, + &recipient, identity_nonce_counter, - signer, // This means the TUI loaded identity must always be the sender since we're always signing with it for now + signer, // This means in the TUI, the loaded identity must always be the sender since we're always signing with it for now transfer_info.amount, ); operations.push(state_transition); } else if current_identities.len() > 1 { + // Handle the case where no sender, recipient, and amount are provided + let identities_count = current_identities.len(); if identities_count == 0 { break; From 4bc0a653de328adacae4e8e85ab6971c42984786 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Tue, 5 Nov 2024 16:19:48 +0700 Subject: [PATCH 08/40] let transfer keys be any security level or key type --- packages/strategy-tests/src/transitions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/strategy-tests/src/transitions.rs b/packages/strategy-tests/src/transitions.rs index c77b51e2903..a9cb113d83c 100644 --- a/packages/strategy-tests/src/transitions.rs +++ b/packages/strategy-tests/src/transitions.rs @@ -824,8 +824,8 @@ pub fn create_identity_credit_transfer_transition( let identity_public_key = identity .get_first_public_key_matching( Purpose::TRANSFER, - HashSet::from([SecurityLevel::CRITICAL]), - HashSet::from([KeyType::ECDSA_SECP256K1, KeyType::BLS12_381]), + SecurityLevel::full_range().into(), + KeyType::all_key_types().into(), false, ) .expect("expected to get a signing key"); From dc4882725f6ed6f7a6e4bc8835d84d95bd4ec41f Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Tue, 5 Nov 2024 17:44:37 +0700 Subject: [PATCH 09/40] fix --- packages/strategy-tests/src/transitions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/strategy-tests/src/transitions.rs b/packages/strategy-tests/src/transitions.rs index a9cb113d83c..c77b51e2903 100644 --- a/packages/strategy-tests/src/transitions.rs +++ b/packages/strategy-tests/src/transitions.rs @@ -824,8 +824,8 @@ pub fn create_identity_credit_transfer_transition( let identity_public_key = identity .get_first_public_key_matching( Purpose::TRANSFER, - SecurityLevel::full_range().into(), - KeyType::all_key_types().into(), + HashSet::from([SecurityLevel::CRITICAL]), + HashSet::from([KeyType::ECDSA_SECP256K1, KeyType::BLS12_381]), false, ) .expect("expected to get a signing key"); From ae97f47b72a9e5a1c914469107865cb971929878 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 6 Nov 2024 21:56:50 +0700 Subject: [PATCH 10/40] ci: run devcontainers workflow only on push to master (#2295) --- .github/workflows/prebuild-devcontainers.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/prebuild-devcontainers.yml b/.github/workflows/prebuild-devcontainers.yml index 794fa3d4a56..1825985c82a 100644 --- a/.github/workflows/prebuild-devcontainers.yml +++ b/.github/workflows/prebuild-devcontainers.yml @@ -7,6 +7,8 @@ on: - '.github/workflows/prebuild-devcontainers.yml' - rust-toolchain.toml - Dockerfile + branches: + - master workflow_dispatch: concurrency: From 48cca1a319505ff7abda72c9a3bb87883d6e8a07 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 6 Nov 2024 21:57:07 +0700 Subject: [PATCH 11/40] ci: do not run test on push (#2308) --- .github/workflows/tests.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c823d0cd061..cca5f1c471d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,12 +7,6 @@ on: branches: - master - 'v[0-9]+\.[0-9]+-dev' - push: - branches: - - master - - 'v[0-9]+\.[0-9]+-dev' - schedule: - - cron: "30 4 * * *" concurrency: group: ${{ github.workflow }}-${{ github.ref }} From 5c80069de3937c439b9646321df3951c57406e32 Mon Sep 17 00:00:00 2001 From: lklimek <842586+lklimek@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:50:04 +0100 Subject: [PATCH 12/40] ci: use prebuilt librocksdb in github actions (#2316) --- .github/actions/librocksdb/action.yaml | 55 ++++++++++++++++++++++ .github/workflows/cached.yml | 23 +++++++++ .github/workflows/docs.yml | 2 +- .github/workflows/manage-runs.yml | 2 +- .github/workflows/pr.yml | 2 +- .github/workflows/release-docker-image.yml | 2 +- .github/workflows/release.yml | 6 +-- .github/workflows/tests-codeql.yml | 2 +- .github/workflows/tests-js-package.yml | 4 +- .github/workflows/tests-rs-package.yml | 37 +++++++++++++-- .github/workflows/tests.yml | 40 ++++++++++++---- 11 files changed, 152 insertions(+), 23 deletions(-) create mode 100644 .github/actions/librocksdb/action.yaml create mode 100644 .github/workflows/cached.yml diff --git a/.github/actions/librocksdb/action.yaml b/.github/actions/librocksdb/action.yaml new file mode 100644 index 00000000000..895185f43dd --- /dev/null +++ b/.github/actions/librocksdb/action.yaml @@ -0,0 +1,55 @@ +--- +# This action builds and caches librocksdb. If we find that this solution consumes too much time, we can consider +# prebuilding librocksdb outside of the pipeline (eg. in the grovedb release process), publish as an artifact, and +# download it in the pipeline. +name: "librocksdb" +description: "Build and install librocksdb" +inputs: + version: + description: RocksDB version, eg. "8.10.2" + required: false + default: "8.10.2" + bucket: + description: S3 bucket to use for caching + required: false + default: multi-runner-cache-x1xibo9c + force: + description: Force rebuild + required: false + default: "false" + +runs: + using: composite + steps: + # Cache librocksdb using s3 bucket + - name: Restore cached librocksdb from S3 + id: librocksdb-cache + uses: strophy/actions-cache@opendal-update + with: + bucket: ${{ inputs.bucket }} + path: /opt/rocksdb + key: librocksdb/${{ inputs.version }}/${{ runner.os }}/${{ runner.arch }} + + - if: ${{ steps.librocksdb-cache.outputs.cache-hit != 'true' || inputs.force == 'true' }} + shell: bash + name: Build librocksdb + run: | + set -ex + WORKDIR=/tmp/rocksdb-build + mkdir -p ${WORKDIR}/rocksdb + mkdir -p /opt/rocksdb/usr/local/lib/ + pushd ${WORKDIR}/rocksdb + + # building rocksdb + git clone https://github.com/facebook/rocksdb.git -b v${{ inputs.version }} --depth 1 . + make -j$(nproc) static_lib + make DESTDIR=/opt/rocksdb install-static + set +x + + echo Done. + echo Configuration: + echo + echo "ROCKSDB_STATIC='/opt/rocksdb/usr/local/lib/librocksdb.a'" + echo "ROCKSDB_LIB_DIR='/opt/rocksdb/usr/local/lib'" + + popd diff --git a/.github/workflows/cached.yml b/.github/workflows/cached.yml new file mode 100644 index 00000000000..12eed8dd3e8 --- /dev/null +++ b/.github/workflows/cached.yml @@ -0,0 +1,23 @@ +--- +name: Rebuild cached dependencies + +on: + workflow_dispatch: +jobs: + build-rust-deps: + name: Prebuild and cache some Rust dependencies + runs-on: ubuntu-24.04 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: ${{ secrets.AWS_REGION }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + - name: Precompile librocksdb + uses: ./.github/actions/librocksdb + with: + force: true diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 12f512b7208..d8e24ef706f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -7,7 +7,7 @@ on: jobs: build: name: Deploy docs - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Checkout main uses: actions/checkout@v4 diff --git a/.github/workflows/manage-runs.yml b/.github/workflows/manage-runs.yml index 2c07af5b4f3..29bc43aa535 100644 --- a/.github/workflows/manage-runs.yml +++ b/.github/workflows/manage-runs.yml @@ -7,7 +7,7 @@ on: jobs: cancel-merged-or-closed-pr-runs: name: Cancel runs for merged or closed PRs - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - uses: octokit/request-action@v2.x id: get_active_workflows diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index d475a3eef8f..e75151c8413 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -10,7 +10,7 @@ on: jobs: pr-title: name: PR title - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Validate conventional PR title uses: amannn/action-semantic-pull-request@v5 diff --git a/.github/workflows/release-docker-image.yml b/.github/workflows/release-docker-image.yml index 5c56ade272f..54e4cb465a3 100644 --- a/.github/workflows/release-docker-image.yml +++ b/.github/workflows/release-docker-image.yml @@ -89,7 +89,7 @@ jobs: publish-manifest: name: Publish image tags needs: build-image - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Download digests uses: actions/download-artifact@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dba5d592f56..4c43639d3ab 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -208,11 +208,11 @@ jobs: matrix: include: - package_type: tarballs - os: ubuntu-22.04 + os: ubuntu-24.04 - package_type: win - os: ubuntu-22.04 + os: ubuntu-24.04 - package_type: deb - os: ubuntu-22.04 + os: ubuntu-24.04 - package_type: macos os: macos-14 steps: diff --git a/.github/workflows/tests-codeql.yml b/.github/workflows/tests-codeql.yml index d00a66c8dfd..78a3f53aeb7 100644 --- a/.github/workflows/tests-codeql.yml +++ b/.github/workflows/tests-codeql.yml @@ -4,7 +4,7 @@ on: jobs: codeql: name: Run Code QL - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 permissions: actions: read contents: read diff --git a/.github/workflows/tests-js-package.yml b/.github/workflows/tests-js-package.yml index ef508ec0738..bdffc8cd41f 100644 --- a/.github/workflows/tests-js-package.yml +++ b/.github/workflows/tests-js-package.yml @@ -17,7 +17,7 @@ on: jobs: lint: name: Linting - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 permissions: id-token: write contents: read @@ -51,7 +51,7 @@ jobs: test: name: Tests - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 permissions: id-token: write contents: read diff --git a/.github/workflows/tests-rs-package.yml b/.github/workflows/tests-rs-package.yml index e666491ebcf..a05e68ee6ce 100644 --- a/.github/workflows/tests-rs-package.yml +++ b/.github/workflows/tests-rs-package.yml @@ -12,7 +12,7 @@ on: lint-runner: description: Runner for linting. Must be JSON valid string. type: string - default: '"ubuntu-22.04"' + default: '"ubuntu-24.04"' check-each-feature: description: If true, try to build each individual feature for this crate type: boolean @@ -42,6 +42,9 @@ jobs: with: components: clippy + - name: Install librocksdb + uses: ./.github/actions/librocksdb + - uses: clechasseur/rs-clippy-check@v3 with: args: --package ${{ inputs.package }} --all-features --locked -- --no-deps @@ -50,10 +53,12 @@ jobs: SCCACHE_BUCKET: multi-runner-cache-x1xibo9c SCCACHE_REGION: ${{ secrets.AWS_REGION }} SCCACHE_S3_KEY_PREFIX: ${{ runner.os }}/sccache/${{ runner.arch }}/linux-gnu + ROCKSDB_STATIC: "/opt/rocksdb/usr/local/lib/librocksdb.a" + ROCKSDB_LIB_DIR: "/opt/rocksdb/usr/local/lib" formatting: name: Formatting - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 timeout-minutes: 5 steps: - name: Check out repo @@ -65,12 +70,19 @@ jobs: components: rustfmt cache: false + # This step doesn't need librocksdb, so we don't install it + - name: Check formatting + env: + RUSTC_WRAPPER: sccache + SCCACHE_BUCKET: multi-runner-cache-x1xibo9c + SCCACHE_REGION: ${{ secrets.AWS_REGION }} + SCCACHE_S3_KEY_PREFIX: ${{ runner.os }}/sccache/${{ runner.arch }}/linux-gnu run: cargo fmt --check --package=${{ inputs.package }} unused_deps: name: Unused dependencies - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 permissions: id-token: write contents: read @@ -89,6 +101,9 @@ jobs: - name: Setup Rust uses: ./.github/actions/rust + - name: Install librocksdb + uses: ./.github/actions/librocksdb + - name: Get crate ${{ inputs.package }} info id: crate_info uses: ./.github/actions/crate_info @@ -102,12 +117,14 @@ jobs: SCCACHE_BUCKET: multi-runner-cache-x1xibo9c SCCACHE_REGION: ${{ secrets.AWS_REGION }} SCCACHE_S3_KEY_PREFIX: ${{ runner.os }}/sccache/${{ runner.arch }}/linux-gnu + ROCKSDB_STATIC: "/opt/rocksdb/usr/local/lib/librocksdb.a" + ROCKSDB_LIB_DIR: "/opt/rocksdb/usr/local/lib" with: args: ${{ steps.crate_info.outputs.cargo_manifest_dir }} detect_structure_changes: name: Detect immutable structure changes - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 # FIXME: as we use `gh pr view` below, this check can only # run on pull requests. We should find a way to run it # when manual triggers are used. @@ -184,6 +201,9 @@ jobs: - name: Setup Rust uses: ./.github/actions/rust + - name: Install librocksdb + uses: ./.github/actions/librocksdb + - name: Run tests run: cargo test --package=${{ inputs.package }} --all-features --locked env: @@ -191,6 +211,8 @@ jobs: SCCACHE_BUCKET: multi-runner-cache-x1xibo9c SCCACHE_REGION: ${{ secrets.AWS_REGION }} SCCACHE_S3_KEY_PREFIX: ${{ runner.os }}/sccache/${{ runner.arch }}/linux-gnu + ROCKSDB_STATIC: "/opt/rocksdb/usr/local/lib/librocksdb.a" + ROCKSDB_LIB_DIR: "/opt/rocksdb/usr/local/lib" check_each_feature: name: Check each feature @@ -199,7 +221,7 @@ jobs: if: ${{ inputs.check-each-feature }} steps: - name: Check out repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Configure AWS credentials and bucket region uses: aws-actions/configure-aws-credentials@v4 @@ -211,6 +233,9 @@ jobs: - name: Setup Rust uses: ./.github/actions/rust + - name: Install librocksdb + uses: ./.github/actions/librocksdb + - name: Get crate ${{ runner.arch }} info id: crate_info uses: ./.github/actions/crate_info @@ -223,6 +248,8 @@ jobs: SCCACHE_BUCKET: multi-runner-cache-x1xibo9c SCCACHE_REGION: ${{ secrets.AWS_REGION }} SCCACHE_S3_KEY_PREFIX: ${{ runner.os }}/sccache/${{ runner.arch }}/linux-gnu + ROCKSDB_STATIC: "/opt/rocksdb/usr/local/lib/librocksdb.a" + ROCKSDB_LIB_DIR: "/opt/rocksdb/usr/local/lib" run: | echo Verify all features disabled set -ex diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cca5f1c471d..5f6cec2c08d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,6 +2,11 @@ name: Tests on: workflow_dispatch: + inputs: + rebuild-deps: + description: "Rebuild cached Rust dependencies" + required: false + default: "false" pull_request: types: [opened, synchronize, reopened, ready_for_review] branches: @@ -16,13 +21,13 @@ jobs: changes: name: Determine changed packages if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 outputs: js-packages: ${{ steps.filter-js.outputs.changes }} rs-packages: ${{ steps.filter-rs.outputs.changes }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -36,6 +41,22 @@ jobs: with: filters: .github/package-filters/rs-packages.yml + build-rust-deps: + name: Prebuild and cache some Rust dependencies + runs-on: ubuntu-24.04 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: ${{ secrets.AWS_REGION }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + - name: Precompile librocksdb + uses: ./.github/actions/librocksdb + build-js: name: Build JS packages if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft }} @@ -69,6 +90,7 @@ jobs: name: Rust packages needs: - changes + - build-rust-deps secrets: inherit strategy: fail-fast: false @@ -77,17 +99,19 @@ jobs: uses: ./.github/workflows/tests-rs-package.yml with: package: ${{ matrix.rs-package }} - # lint-runner: ${{ contains(fromJSON('["drive-abci", "drive"]'), matrix.rs-package) && '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]' || '"ubuntu-22.04"' }} + # lint-runner: ${{ contains(fromJSON('["drive-abci", "drive"]'), matrix.rs-package) && '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]' || '"ubuntu-24.04"' }} # FIXME: Clippy fails on github hosted runners, most likely due to RAM usage. Using self-hosted runners for now. - lint-runner: '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]' + # lint-runner: '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]' + lint-runner: '["ubuntu-24.04"]' # Run drive tests on self-hosted 4x - test-runner: '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]' + # test-runner: '[ "self-hosted", "linux", "arm64", "ubuntu-platform" ]' + test-runner: '["ubuntu-24.04"]' check-each-feature: ${{ contains(fromJSON('["dash-sdk","rs-dapi-client","dapi-grpc","dpp","drive-abci"]'), matrix.rs-package) }} rs-crates-security: name: Rust crates security audit if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Check out repo uses: actions/checkout@v4 @@ -116,7 +140,7 @@ jobs: js-deps-versions: name: JS dependency versions check if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Check out repo uses: actions/checkout@v4 @@ -135,7 +159,7 @@ jobs: js-npm-security: name: JS NPM security audit if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Check out repo uses: actions/checkout@v4 From 2b9d7150314759e8919f1f094cc9a146fee1ce3f Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 19:17:24 +0700 Subject: [PATCH 13/40] ci: debug layer cache --- .github/workflows/tests-build-image.yml | 5 +- Dockerfile | 164 ++++++++++++------------ 2 files changed, 85 insertions(+), 84 deletions(-) diff --git a/.github/workflows/tests-build-image.yml b/.github/workflows/tests-build-image.yml index f8b7c830f42..ec4aa423904 100644 --- a/.github/workflows/tests-build-image.yml +++ b/.github/workflows/tests-build-image.yml @@ -17,7 +17,8 @@ on: jobs: build-image: name: Build ${{ inputs.name }} image - runs-on: ["self-hosted", "linux", "arm64", "ubuntu-platform"] +# runs-on: ["self-hosted", "linux", "arm64", "ubuntu-platform"] + runs-on: ubuntu-24.04 steps: - name: Check out repo uses: actions/checkout@v4 @@ -41,7 +42,7 @@ jobs: image_name: ${{ inputs.image_name }} image_org: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com target: ${{ inputs.target }} - platform: linux/arm64 + platform: linux/amd64 push_tags: true dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 5039a062b69..15daa043b08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -158,20 +158,20 @@ WORKDIR /platform # Install wasm-bindgen-cli in the same profile as other components, to sacrifice some performance & disk space to gain # better build caching -RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ - --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ - --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ - --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ - export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ - source $HOME/.cargo/env && \ - if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ - RUSTFLAGS="-C target-feature=-crt-static" \ - CARGO_TARGET_DIR="/platform/target" \ - # TODO: Build wasm with build.rs - # Meanwhile if you want to update wasm-bindgen you also need to update version in: - # - packages/wasm-dpp/Cargo.toml - # - packages/wasm-dpp/scripts/build-wasm.sh - cargo install --profile "$CARGO_BUILD_PROFILE" wasm-bindgen-cli@0.2.86 cargo-chef@0.1.67 --locked +#RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ +# --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ +# --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ +# --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ +# export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ +# source $HOME/.cargo/env && \ +# if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ +# RUSTFLAGS="-C target-feature=-crt-static" \ +# CARGO_TARGET_DIR="/platform/target" \ +# # TODO: Build wasm with build.rs +# # Meanwhile if you want to update wasm-bindgen you also need to update version in: +# # - packages/wasm-dpp/Cargo.toml +# # - packages/wasm-dpp/scripts/build-wasm.sh +# cargo install --profile "$CARGO_BUILD_PROFILE" wasm-bindgen-cli@0.2.86 cargo-chef@0.1.67 --locked # # Rust build planner to speed up builds @@ -179,8 +179,8 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM FROM deps AS build-planner WORKDIR /platform COPY . . -RUN source $HOME/.cargo/env && \ - cargo chef prepare --recipe-path recipe.json +#RUN source $HOME/.cargo/env && \ +# cargo chef prepare --recipe-path recipe.json # Workaround: as we cache dapi-grpc, its build.rs is not rerun, so we need to touch it RUN touch /platform/packages/dapi-grpc/build.rs @@ -201,47 +201,47 @@ WORKDIR /platform COPY --from=build-planner /platform/recipe.json recipe.json # Build dependencies - this is the caching Docker layer! -RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ - --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ - --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ - --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ - source $HOME/.cargo/env && \ - export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ - if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ - cargo chef cook \ - --recipe-path recipe.json \ - --profile "$CARGO_BUILD_PROFILE" \ - --package drive-abci \ - --locked && \ - if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi +#RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ +# --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ +# --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ +# --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ +# source $HOME/.cargo/env && \ +# export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ +# if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ +# cargo chef cook \ +# --recipe-path recipe.json \ +# --profile "$CARGO_BUILD_PROFILE" \ +# --package drive-abci \ +# --locked && \ +# if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi COPY . . RUN mkdir /artifacts # Build Drive ABCI -RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ - --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ - --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ - --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ - source $HOME/.cargo/env && \ - export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ - if [[ "${CARGO_BUILD_PROFILE}" == "release" ]] ; then \ - mv .cargo/config-release.toml .cargo/config.toml && \ - export OUT_DIRECTORY=release ; \ - else \ - export FEATURES_FLAG="--features=console,grovedbg" ; \ - export OUT_DIRECTORY=debug ; \ - - fi && \ - if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ - cargo build \ - --profile "${CARGO_BUILD_PROFILE}" \ - --package drive-abci \ - ${FEATURES_FLAG} \ - --locked && \ - cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \ - if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi +#RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ +# --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ +# --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ +# --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ +# source $HOME/.cargo/env && \ +# export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ +# if [[ "${CARGO_BUILD_PROFILE}" == "release" ]] ; then \ +# mv .cargo/config-release.toml .cargo/config.toml && \ +# export OUT_DIRECTORY=release ; \ +# else \ +# export FEATURES_FLAG="--features=console,grovedbg" ; \ +# export OUT_DIRECTORY=debug ; \ +# +# fi && \ +# if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ +# cargo build \ +# --profile "${CARGO_BUILD_PROFILE}" \ +# --package drive-abci \ +# ${FEATURES_FLAG} \ +# --locked && \ +# cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \ +# if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi # # STAGE: BUILD JAVASCRIPT INTERMEDIATE IMAGE @@ -253,40 +253,40 @@ ENV SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}/wasm/wasm32 WORKDIR /platform -COPY --from=build-planner /platform/recipe.json recipe.json +#COPY --from=build-planner /platform/recipe.json recipe.json # Build dependencies - this is the caching Docker layer! -RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ - --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ - --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ - --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ - source $HOME/.cargo/env && \ - export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ - if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ - cargo chef cook \ - --recipe-path recipe.json \ - --profile "$CARGO_BUILD_PROFILE" \ - --package wasm-dpp \ - --target wasm32-unknown-unknown \ - --locked && \ - if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi +#RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ +# --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ +# --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ +# --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ +# source $HOME/.cargo/env && \ +# export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ +# if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ +# cargo chef cook \ +# --recipe-path recipe.json \ +# --profile "$CARGO_BUILD_PROFILE" \ +# --package wasm-dpp \ +# --target wasm32-unknown-unknown \ +# --locked && \ +# if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi COPY . . -RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ - --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ - --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ - --mount=type=cache,sharing=shared,id=target_wasm,target=/platform/target \ - --mount=type=cache,sharing=shared,id=unplugged_${TARGETARCH},target=/tmp/unplugged \ - source $HOME/.cargo/env && \ - cp -R /tmp/unplugged /platform/.yarn/ && \ - yarn install --inline-builds && \ - cp -R /platform/.yarn/unplugged /tmp/ && \ - export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ - if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ - export SKIP_GRPC_PROTO_BUILD=1 && \ - yarn build && \ - if [[ "${RUSTC_WRAPPER}" == "sccache" ]]; then sccache --show-stats; fi +#RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ +# --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ +# --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ +# --mount=type=cache,sharing=shared,id=target_wasm,target=/platform/target \ +# --mount=type=cache,sharing=shared,id=unplugged_${TARGETARCH},target=/tmp/unplugged \ +# source $HOME/.cargo/env && \ +# cp -R /tmp/unplugged /platform/.yarn/ && \ +# yarn install --inline-builds && \ +# cp -R /platform/.yarn/unplugged /tmp/ && \ +# export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ +# if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ +# export SKIP_GRPC_PROTO_BUILD=1 && \ +# yarn build && \ +# if [[ "${RUSTC_WRAPPER}" == "sccache" ]]; then sccache --show-stats; fi # # STAGE: FINAL DRIVE-ABCI IMAGE @@ -305,7 +305,7 @@ RUN mkdir -p /var/log/dash \ /var/lib/dash/rs-drive-abci/db \ ${REJECTIONS_PATH} -COPY --from=build-drive-abci /artifacts/drive-abci /usr/bin/drive-abci +#COPY --from=build-drive-abci /artifacts/drive-abci /usr/bin/drive-abci COPY --from=build-drive-abci /platform/packages/rs-drive-abci/.env.mainnet /var/lib/dash/rs-drive-abci/.env # Create a volume @@ -313,7 +313,7 @@ VOLUME /var/lib/dash/rs-drive-abci/db VOLUME /var/log/dash # Double-check that we don't have missing deps -RUN ldd /usr/bin/drive-abci +#RUN ldd /usr/bin/drive-abci # # Create new non-root user From 42fdd64899843c44c4d7cfe71364e03b5105dddc Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 19:32:27 +0700 Subject: [PATCH 14/40] ci: update docker/build-push-action@ --- .github/actions/docker/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index d41ebf4dcfc..900d823f6e7 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -94,7 +94,7 @@ runs: - name: Build and push Docker image ${{ inputs.image }} id: docker_build - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . builder: ${{ steps.buildx.outputs.name }} From fe231e24c56dfe92788e74be61d8c4fc4e8f8da7 Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 19:40:15 +0700 Subject: [PATCH 15/40] ci: try gha cache --- .github/actions/docker/action.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 900d823f6e7..e1927e3264f 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -110,8 +110,10 @@ runs: SCCACHE_S3_KEY_PREFIX=${{ runner.os }}/sccache AWS_ACCESS_KEY_ID=${{ inputs.aws_access_key_id }} AWS_SECRET_ACCESS_KEY=${{ inputs.aws_secret_access_key }} - cache-from: ${{ steps.layer_cache_settings.outputs.cache_from }} - cache-to: ${{ steps.layer_cache_settings.outputs.cache_to }} + #cache-from: ${{ steps.layer_cache_settings.outputs.cache_from }} + cache-from: type=gha + #cache-to: ${{ steps.layer_cache_settings.outputs.cache_to }} + cache-to: type=gha,mode=max outputs: type=image,name=${{ inputs.image_org }}/${{ inputs.image_name }},push-by-digest=${{ inputs.push_tags != 'true' }},name-canonical=true,push=true - name: Save Docker mount cache From 626a632e45ab4ebfa709b9712e12ed01b912ae2b Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 19:50:01 +0700 Subject: [PATCH 16/40] ci: pass push --- .github/actions/docker/action.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index e1927e3264f..897daf06186 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -69,12 +69,12 @@ runs: [worker.oci] gc = false - - name: Load Docker mount cache - uses: dcginfra/buildkit-cache-dance/inject@s5cmd - if: ${{ inputs.cache_mounts != '' }} - with: - bucket: ${{ inputs.bucket }} - mounts: ${{ inputs.cache_mounts }} +# - name: Load Docker mount cache +# uses: dcginfra/buildkit-cache-dance/inject@s5cmd +# if: ${{ inputs.cache_mounts != '' }} +# with: +# bucket: ${{ inputs.bucket }} +# mounts: ${{ inputs.cache_mounts }} - name: Set Docker tags and labels from image tag id: docker_meta @@ -100,6 +100,7 @@ runs: builder: ${{ steps.buildx.outputs.name }} target: ${{ inputs.target }} labels: ${{ steps.docker_meta.outputs.labels }} + push: ${{ inputs.push_tags }} tags: ${{ inputs.push_tags == 'true' && steps.docker_meta.outputs.tags || '' }} platforms: ${{ inputs.platform }} build-args: | From 5a9d214a5325676538d9c8436a60da2da6b8405e Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 20:17:44 +0700 Subject: [PATCH 17/40] ci: disable mount cache --- .github/actions/docker/action.yaml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 897daf06186..bf6b195b57c 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -85,12 +85,12 @@ runs: type=semver,pattern={{version}},value=${{inputs.image_version}},enable=${{ inputs.image_version != '' }} type=sha,format=long,enable=${{ inputs.image_version == '' }} - - name: Configure docker layer cache - uses: ./.github/actions/s3-layer-cache-settings - id: layer_cache_settings - with: - name: ${{ inputs.image_name }} - bucket: ${{ inputs.bucket }} +# - name: Configure docker layer cache +# uses: ./.github/actions/s3-layer-cache-settings +# id: layer_cache_settings +# with: +# name: ${{ inputs.image_name }} +# bucket: ${{ inputs.bucket }} - name: Build and push Docker image ${{ inputs.image }} id: docker_build @@ -117,9 +117,9 @@ runs: cache-to: type=gha,mode=max outputs: type=image,name=${{ inputs.image_org }}/${{ inputs.image_name }},push-by-digest=${{ inputs.push_tags != 'true' }},name-canonical=true,push=true - - name: Save Docker mount cache - uses: dcginfra/buildkit-cache-dance/extract@s5cmd - if: ${{ inputs.cache_mounts != '' }} - with: - bucket: ${{ inputs.bucket }} - mounts: ${{ inputs.cache_mounts }} +# - name: Save Docker mount cache +# uses: dcginfra/buildkit-cache-dance/extract@s5cmd +# if: ${{ inputs.cache_mounts != '' }} +# with: +# bucket: ${{ inputs.bucket }} +# mounts: ${{ inputs.cache_mounts }} From a3330498fb32e3de7a46f0f6f82886b324d3db5b Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 20:18:56 +0700 Subject: [PATCH 18/40] build: uncomment code in Dockerfile --- Dockerfile | 165 +++++++++++++++++++++++++++-------------------------- 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/Dockerfile b/Dockerfile index 15daa043b08..cb4a1d9c79d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -156,22 +156,23 @@ ENV SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}/${TARGETARCH}/linux-musl WORKDIR /platform +# TODO: Use https://github.com/cargo-bins/cargo-binstall # Install wasm-bindgen-cli in the same profile as other components, to sacrifice some performance & disk space to gain # better build caching -#RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ -# --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ -# --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ -# --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ -# export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ -# source $HOME/.cargo/env && \ -# if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ -# RUSTFLAGS="-C target-feature=-crt-static" \ -# CARGO_TARGET_DIR="/platform/target" \ -# # TODO: Build wasm with build.rs -# # Meanwhile if you want to update wasm-bindgen you also need to update version in: -# # - packages/wasm-dpp/Cargo.toml -# # - packages/wasm-dpp/scripts/build-wasm.sh -# cargo install --profile "$CARGO_BUILD_PROFILE" wasm-bindgen-cli@0.2.86 cargo-chef@0.1.67 --locked +RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ + --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ + --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ + --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ + export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ + source $HOME/.cargo/env && \ + if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ + RUSTFLAGS="-C target-feature=-crt-static" \ + CARGO_TARGET_DIR="/platform/target" \ + # TODO: Build wasm with build.rs + # Meanwhile if you want to update wasm-bindgen you also need to update version in: + # - packages/wasm-dpp/Cargo.toml + # - packages/wasm-dpp/scripts/build-wasm.sh + cargo install --profile "$CARGO_BUILD_PROFILE" wasm-bindgen-cli@0.2.86 cargo-chef@0.1.67 --locked # # Rust build planner to speed up builds @@ -179,8 +180,8 @@ WORKDIR /platform FROM deps AS build-planner WORKDIR /platform COPY . . -#RUN source $HOME/.cargo/env && \ -# cargo chef prepare --recipe-path recipe.json +RUN source $HOME/.cargo/env && \ + cargo chef prepare --recipe-path recipe.json # Workaround: as we cache dapi-grpc, its build.rs is not rerun, so we need to touch it RUN touch /platform/packages/dapi-grpc/build.rs @@ -201,47 +202,47 @@ WORKDIR /platform COPY --from=build-planner /platform/recipe.json recipe.json # Build dependencies - this is the caching Docker layer! -#RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ -# --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ -# --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ -# --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ -# source $HOME/.cargo/env && \ -# export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ -# if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ -# cargo chef cook \ -# --recipe-path recipe.json \ -# --profile "$CARGO_BUILD_PROFILE" \ -# --package drive-abci \ -# --locked && \ -# if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi +RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ + --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ + --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ + --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ + source $HOME/.cargo/env && \ + export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ + if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ + cargo chef cook \ + --recipe-path recipe.json \ + --profile "$CARGO_BUILD_PROFILE" \ + --package drive-abci \ + --locked && \ + if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi COPY . . RUN mkdir /artifacts # Build Drive ABCI -#RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ -# --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ -# --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ -# --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ -# source $HOME/.cargo/env && \ -# export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ -# if [[ "${CARGO_BUILD_PROFILE}" == "release" ]] ; then \ -# mv .cargo/config-release.toml .cargo/config.toml && \ -# export OUT_DIRECTORY=release ; \ -# else \ -# export FEATURES_FLAG="--features=console,grovedbg" ; \ -# export OUT_DIRECTORY=debug ; \ -# -# fi && \ -# if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ -# cargo build \ -# --profile "${CARGO_BUILD_PROFILE}" \ -# --package drive-abci \ -# ${FEATURES_FLAG} \ -# --locked && \ -# cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \ -# if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi +RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ + --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ + --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ + --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ + source $HOME/.cargo/env && \ + export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ + if [[ "${CARGO_BUILD_PROFILE}" == "release" ]] ; then \ + mv .cargo/config-release.toml .cargo/config.toml && \ + export OUT_DIRECTORY=release ; \ + else \ + export FEATURES_FLAG="--features=console,grovedbg" ; \ + export OUT_DIRECTORY=debug ; \ + + fi && \ + if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ + cargo build \ + --profile "${CARGO_BUILD_PROFILE}" \ + --package drive-abci \ + ${FEATURES_FLAG} \ + --locked && \ + cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \ + if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi # # STAGE: BUILD JAVASCRIPT INTERMEDIATE IMAGE @@ -253,40 +254,40 @@ ENV SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}/wasm/wasm32 WORKDIR /platform -#COPY --from=build-planner /platform/recipe.json recipe.json +COPY --from=build-planner /platform/recipe.json recipe.json # Build dependencies - this is the caching Docker layer! -#RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ -# --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ -# --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ -# --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ -# source $HOME/.cargo/env && \ -# export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ -# if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ -# cargo chef cook \ -# --recipe-path recipe.json \ -# --profile "$CARGO_BUILD_PROFILE" \ -# --package wasm-dpp \ -# --target wasm32-unknown-unknown \ -# --locked && \ -# if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi +RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ + --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ + --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ + --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ + source $HOME/.cargo/env && \ + export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ + if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ + cargo chef cook \ + --recipe-path recipe.json \ + --profile "$CARGO_BUILD_PROFILE" \ + --package wasm-dpp \ + --target wasm32-unknown-unknown \ + --locked && \ + if [[ "${RUSTC_WRAPPER}" == "sccache" ]] ; then sccache --show-stats; fi COPY . . -#RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ -# --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ -# --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ -# --mount=type=cache,sharing=shared,id=target_wasm,target=/platform/target \ -# --mount=type=cache,sharing=shared,id=unplugged_${TARGETARCH},target=/tmp/unplugged \ -# source $HOME/.cargo/env && \ -# cp -R /tmp/unplugged /platform/.yarn/ && \ -# yarn install --inline-builds && \ -# cp -R /platform/.yarn/unplugged /tmp/ && \ -# export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ -# if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ -# export SKIP_GRPC_PROTO_BUILD=1 && \ -# yarn build && \ -# if [[ "${RUSTC_WRAPPER}" == "sccache" ]]; then sccache --show-stats; fi +RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ + --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ + --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ + --mount=type=cache,sharing=shared,id=target_wasm,target=/platform/target \ + --mount=type=cache,sharing=shared,id=unplugged_${TARGETARCH},target=/tmp/unplugged \ + source $HOME/.cargo/env && \ + cp -R /tmp/unplugged /platform/.yarn/ && \ + yarn install --inline-builds && \ + cp -R /platform/.yarn/unplugged /tmp/ && \ + export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ + if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ + export SKIP_GRPC_PROTO_BUILD=1 && \ + yarn build && \ + if [[ "${RUSTC_WRAPPER}" == "sccache" ]]; then sccache --show-stats; fi # # STAGE: FINAL DRIVE-ABCI IMAGE @@ -305,7 +306,7 @@ RUN mkdir -p /var/log/dash \ /var/lib/dash/rs-drive-abci/db \ ${REJECTIONS_PATH} -#COPY --from=build-drive-abci /artifacts/drive-abci /usr/bin/drive-abci +COPY --from=build-drive-abci /artifacts/drive-abci /usr/bin/drive-abci COPY --from=build-drive-abci /platform/packages/rs-drive-abci/.env.mainnet /var/lib/dash/rs-drive-abci/.env # Create a volume @@ -313,7 +314,7 @@ VOLUME /var/lib/dash/rs-drive-abci/db VOLUME /var/log/dash # Double-check that we don't have missing deps -#RUN ldd /usr/bin/drive-abci +RUN ldd /usr/bin/drive-abci # # Create new non-root user From 39e9d43bb147ca8e6c9c06279e1078b67029168b Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 21:01:05 +0700 Subject: [PATCH 19/40] ci: store cargo and yarn cache mounts --- .github/actions/docker/action.yaml | 57 ++++++++++++++++++++++++++++++ Dockerfile | 1 - 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index bf6b195b57c..8c83be49fe3 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -92,6 +92,63 @@ runs: # name: ${{ inputs.image_name }} # bucket: ${{ inputs.bucket }} + RUN --mount=type=cache,sharing=shared,id=,target=${CARGO_HOME}/registry/index \ + --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ + --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ + + - name: Cargo cache for Docker + uses: actions/cache@v4 + id: cargo-cache + with: + path: | + ../cargo-cache-registry-index + ../cargo-cache-registry-cache + ../cargo-cache-git-db + key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} + restore-keys: + - ${{ runner.os }}-cargo- + + - name: Inject cargo cache into docker + uses: reproducible-containers/buildkit-cache-dance@3 + with: + cache-map: | + { + "../cargo-cache-registry-index": { + "target": "/root/.cargo/registry/index", + "id": "cargo_registry_index" + }, + "../cargo-cache-registry-cache": { + "target": "/root/.cargo/registry/cache", + "id": "cargo_registry_index" + }, + "../cargo-cache-git-db": { + "target": "/root/.cargo/git/db", + "id": "cargo_registry_index" + }, + } + skip-extraction: ${{ steps.cargo-cache.outputs.cache-hit }} + + - name: Yarn unplugged cache for Docker + uses: actions/cache@v4 + id: yarn-cache + with: + path: ../yarn-unplugged-cache + key: ${{ runner.os }}-yarn-unplugged-amd64-${{ hashFiles('yarn.lock') }} + restore-keys: + - ${{ runner.os }}-yarn-unplugged-amd64- + + - name: Inject cargo cache into docker + uses: reproducible-containers/buildkit-cache-dance@3 + with: + cache-map: | + { + "../yarn-unplugged-cache": { + "target": "/tmp/unplugged", + "id": "unplugged_amd64" + }, + } + skip-extraction: ${{ steps.yarn-cache.outputs.cache-hit }} + - name: Build and push Docker image ${{ inputs.image }} id: docker_build uses: docker/build-push-action@v6 diff --git a/Dockerfile b/Dockerfile index cb4a1d9c79d..92bffdc8e40 100644 --- a/Dockerfile +++ b/Dockerfile @@ -233,7 +233,6 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM else \ export FEATURES_FLAG="--features=console,grovedbg" ; \ export OUT_DIRECTORY=debug ; \ - fi && \ if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ cargo build \ From d6cbbc2f50c0549160f30da58acaf25c4da06685 Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 21:11:50 +0700 Subject: [PATCH 20/40] ci: remove garbage --- .github/actions/docker/action.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 8c83be49fe3..0df2a63b133 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -92,10 +92,6 @@ runs: # name: ${{ inputs.image_name }} # bucket: ${{ inputs.bucket }} - RUN --mount=type=cache,sharing=shared,id=,target=${CARGO_HOME}/registry/index \ - --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ - --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ - - name: Cargo cache for Docker uses: actions/cache@v4 id: cargo-cache From e31d501208e82f6d46a7aa8bf6c1d6b77d698810 Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 21:14:34 +0700 Subject: [PATCH 21/40] ci: fix restore keys --- .github/actions/docker/action.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 0df2a63b133..6addc5a1d90 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -101,8 +101,8 @@ runs: ../cargo-cache-registry-cache ../cargo-cache-git-db key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} - restore-keys: - - ${{ runner.os }}-cargo- + restore-keys: | + - ${{ runner.os }}-cargo- - name: Inject cargo cache into docker uses: reproducible-containers/buildkit-cache-dance@3 @@ -130,7 +130,7 @@ runs: with: path: ../yarn-unplugged-cache key: ${{ runner.os }}-yarn-unplugged-amd64-${{ hashFiles('yarn.lock') }} - restore-keys: + restore-keys: | - ${{ runner.os }}-yarn-unplugged-amd64- - name: Inject cargo cache into docker From 63c3d501d63ece4fd6a1390245f37328b71678f1 Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 21:17:13 +0700 Subject: [PATCH 22/40] ci: specify correct version --- .github/actions/docker/action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 6addc5a1d90..eea2abec607 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -105,7 +105,7 @@ runs: - ${{ runner.os }}-cargo- - name: Inject cargo cache into docker - uses: reproducible-containers/buildkit-cache-dance@3 + uses: reproducible-containers/buildkit-cache-dance@v3.1.2 with: cache-map: | { @@ -134,7 +134,7 @@ runs: - ${{ runner.os }}-yarn-unplugged-amd64- - name: Inject cargo cache into docker - uses: reproducible-containers/buildkit-cache-dance@3 + uses: reproducible-containers/buildkit-cache-dance@v3.1.2 with: cache-map: | { From 9ca6ffd6d82beaee752d882dbdf41a0ceda5463e Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 21:18:58 +0700 Subject: [PATCH 23/40] ci: fix expected JSON --- .github/actions/docker/action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index eea2abec607..79b52456888 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -120,7 +120,7 @@ runs: "../cargo-cache-git-db": { "target": "/root/.cargo/git/db", "id": "cargo_registry_index" - }, + } } skip-extraction: ${{ steps.cargo-cache.outputs.cache-hit }} @@ -141,7 +141,7 @@ runs: "../yarn-unplugged-cache": { "target": "/tmp/unplugged", "id": "unplugged_amd64" - }, + } } skip-extraction: ${{ steps.yarn-cache.outputs.cache-hit }} From 698a8a803f9d4c9cf9006247254552e701cba77d Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 21:48:40 +0700 Subject: [PATCH 24/40] build: remove random port --- .github/actions/docker/action.yaml | 1 + Dockerfile | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 79b52456888..9cd95cbff05 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -129,6 +129,7 @@ runs: id: yarn-cache with: path: ../yarn-unplugged-cache + # TODO: We should use platform input key: ${{ runner.os }}-yarn-unplugged-amd64-${{ hashFiles('yarn.lock') }} restore-keys: | - ${{ runner.os }}-yarn-unplugged-amd64- diff --git a/Dockerfile b/Dockerfile index 92bffdc8e40..3b1eb273152 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,6 @@ # 2. We add `--config net.git-fetch-with-cli=true` to address ARM build issue, # see https://github.com/rust-lang/cargo/issues/10781#issuecomment-1441071052 # 3. Github Actions have shared networking configured, so we need to set a random -# SCCACHE_SERVER_PORT port to avoid conflicts in case of parallel compilation ARG ALPINE_VERSION=3.18 ARG PROTOC_VERSION=27.3 @@ -163,7 +162,6 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ - export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ source $HOME/.cargo/env && \ if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ RUSTFLAGS="-C target-feature=-crt-static" \ @@ -207,7 +205,6 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ source $HOME/.cargo/env && \ - export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ cargo chef cook \ --recipe-path recipe.json \ @@ -226,7 +223,6 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ source $HOME/.cargo/env && \ - export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ if [[ "${CARGO_BUILD_PROFILE}" == "release" ]] ; then \ mv .cargo/config-release.toml .cargo/config.toml && \ export OUT_DIRECTORY=release ; \ @@ -261,7 +257,6 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ source $HOME/.cargo/env && \ - export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ cargo chef cook \ --recipe-path recipe.json \ @@ -282,7 +277,6 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM cp -R /tmp/unplugged /platform/.yarn/ && \ yarn install --inline-builds && \ cp -R /platform/.yarn/unplugged /tmp/ && \ - export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ export SKIP_GRPC_PROTO_BUILD=1 && \ yarn build && \ From ba2e47722943bb7ecf0d20e8e7c868a0aced0ad1 Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 21:59:41 +0700 Subject: [PATCH 25/40] ci: switch build js to free runner --- .github/workflows/tests-build-js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests-build-js.yml b/.github/workflows/tests-build-js.yml index a367af55fc8..bc67850ad99 100644 --- a/.github/workflows/tests-build-js.yml +++ b/.github/workflows/tests-build-js.yml @@ -4,7 +4,7 @@ on: jobs: build-js: name: Build JS - runs-on: ["self-hosted", "linux", "arm64", "ubuntu-platform"] + runs-on: ubuntu-24.04 steps: - name: Configure AWS credentials and bucket region uses: aws-actions/configure-aws-credentials@v4 From 7531fc904e0e96f11ec66b784932fb41af2643e5 Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Fri, 8 Nov 2024 22:18:04 +0700 Subject: [PATCH 26/40] ci: cleanup --- .github/actions/docker/action.yaml | 12 ++++++------ .github/workflows/tests-build-image.yml | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 9cd95cbff05..07ad1abb9bc 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -22,12 +22,12 @@ inputs: description: User name to use when pushing images to Docker Hub dockerhub_token: description: Docker Hub token to use - cache_mounts: - description: Load cache mounts cache - default: | - cargo_registry_index - cargo_registry_cache - cargo_git +# cache_mounts: +# description: Load cache mounts cache +# default: | +# cargo_registry_index +# cargo_registry_cache +# cargo_git cargo_profile: description: Cargo build profile, i.e release or dev default: dev diff --git a/.github/workflows/tests-build-image.yml b/.github/workflows/tests-build-image.yml index ec4aa423904..328a6ce2d4c 100644 --- a/.github/workflows/tests-build-image.yml +++ b/.github/workflows/tests-build-image.yml @@ -17,7 +17,6 @@ on: jobs: build-image: name: Build ${{ inputs.name }} image -# runs-on: ["self-hosted", "linux", "arm64", "ubuntu-platform"] runs-on: ubuntu-24.04 steps: - name: Check out repo From 25c31a647364319549c3f5803887680aa603d7cb Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 11 Nov 2024 17:57:47 +0700 Subject: [PATCH 27/40] ci: use platform input for unplugged cache --- .github/actions/docker/action.yaml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 07ad1abb9bc..7b2fee2c042 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -130,19 +130,16 @@ runs: with: path: ../yarn-unplugged-cache # TODO: We should use platform input - key: ${{ runner.os }}-yarn-unplugged-amd64-${{ hashFiles('yarn.lock') }} + key: ${{ inputs.platform }}-yarn-unplugged-${{ hashFiles('yarn.lock') }} restore-keys: | - - ${{ runner.os }}-yarn-unplugged-amd64- + - ${{ inputs.platform }}-yarn-unplugged-amd64- - name: Inject cargo cache into docker uses: reproducible-containers/buildkit-cache-dance@v3.1.2 with: cache-map: | { - "../yarn-unplugged-cache": { - "target": "/tmp/unplugged", - "id": "unplugged_amd64" - } + "../yarn-unplugged-cache": "/tmp/unplugged" } skip-extraction: ${{ steps.yarn-cache.outputs.cache-hit }} From 01e09b6a2c73a29c2059f8730676a4f213aa7912 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 11 Nov 2024 18:51:15 +0700 Subject: [PATCH 28/40] ci: switch to free runners --- .github/workflows/tests-dashmate.yml | 4 ++-- .github/workflows/tests-packges-functional.yml | 2 +- .github/workflows/tests-test-suite.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests-dashmate.yml b/.github/workflows/tests-dashmate.yml index 369c72e06a1..557c755af41 100644 --- a/.github/workflows/tests-dashmate.yml +++ b/.github/workflows/tests-dashmate.yml @@ -17,8 +17,7 @@ on: jobs: dashmate-test: name: Run ${{ inputs.name }} tests - # TODO: Try with Github Runner, probably it will be the same time - runs-on: [ "self-hosted", "linux", "arm64", "ubuntu-platform" ] + runs-on: ubuntu-24.04 timeout-minutes: 15 steps: - name: Check out repo @@ -42,6 +41,7 @@ jobs: - name: Setup Node.JS uses: ./.github/actions/nodejs + # TODO: Use action artifacts - name: Restore JS build artifacts uses: strophy/actions-cache@opendal-update with: diff --git a/.github/workflows/tests-packges-functional.yml b/.github/workflows/tests-packges-functional.yml index 57f735f0d5e..13cfe492e91 100644 --- a/.github/workflows/tests-packges-functional.yml +++ b/.github/workflows/tests-packges-functional.yml @@ -4,7 +4,7 @@ on: jobs: test-functional: name: Run functional tests - runs-on: [ "self-hosted", "linux", "arm64", "ubuntu-platform" ] + runs-on: ubuntu-24.04 timeout-minutes: 15 env: CHROME_BIN: /usr/bin/brave-browser diff --git a/.github/workflows/tests-test-suite.yml b/.github/workflows/tests-test-suite.yml index f1d0ac16212..058395c5040 100644 --- a/.github/workflows/tests-test-suite.yml +++ b/.github/workflows/tests-test-suite.yml @@ -22,7 +22,7 @@ on: jobs: test-suite: name: Run ${{ inputs.name }} - runs-on: [ "self-hosted", "linux", "arm64", "ubuntu-platform" ] + runs-on: ubuntu-24.04 timeout-minutes: 15 env: CHROME_BIN: /usr/bin/brave-browser From 20eed8a1ab9fb50e528023ab02fc8390e86aef9e Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 11 Nov 2024 18:52:49 +0700 Subject: [PATCH 29/40] ci: switch more jobs to free runners --- .github/workflows/prebuild-devcontainers.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prebuild-devcontainers.yml b/.github/workflows/prebuild-devcontainers.yml index 1825985c82a..c7d4ee28f04 100644 --- a/.github/workflows/prebuild-devcontainers.yml +++ b/.github/workflows/prebuild-devcontainers.yml @@ -18,7 +18,7 @@ concurrency: jobs: build: name: Build and push devcontainer - runs-on: ["self-hosted", "linux", "x64", "ubuntu-platform"] + runs-on: ubuntu-24.04 timeout-minutes: 60 steps: - name: Checkout repo diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4c43639d3ab..7584b4f08b5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ concurrency: jobs: release-npm: name: Release NPM packages - runs-on: ["self-hosted", "linux", "arm64", "ubuntu-platform"] + runs-on: ubuntu-24.04 timeout-minutes: 15 if: github.event_name != 'workflow_dispatch' steps: From 3a8b9a11badbccfd67f57ba391113a2a2ef62aed Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 08:57:15 +0700 Subject: [PATCH 30/40] build: fix sccache error --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3b1eb273152..0f8bfd27202 100644 --- a/Dockerfile +++ b/Dockerfile @@ -117,7 +117,7 @@ ARG RUSTC_WRAPPER ENV RUSTC_WRAPPER=${RUSTC_WRAPPER} # Set args below to use Github Actions cache; see https://github.com/mozilla/sccache/blob/main/docs/GHA.md -ARG SCCACHE_GHA_ENABLED +ARG SCCACHE_GHA_ENABLED="false" ENV SCCACHE_GHA_ENABLED=${SCCACHE_GHA_ENABLED} ARG ACTIONS_CACHE_URL From b5e9ea0967126ad94d09decdcb945ce3af59b7fd Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 13:48:44 +0700 Subject: [PATCH 31/40] ci: remove prefix --- .github/actions/docker/action.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 7b2fee2c042..edabf6fde20 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -115,11 +115,11 @@ runs: }, "../cargo-cache-registry-cache": { "target": "/root/.cargo/registry/cache", - "id": "cargo_registry_index" + "id": "cargo_registry_cache" }, "../cargo-cache-git-db": { "target": "/root/.cargo/git/db", - "id": "cargo_registry_index" + "id": "cargo_git" } } skip-extraction: ${{ steps.cargo-cache.outputs.cache-hit }} @@ -129,17 +129,19 @@ runs: id: yarn-cache with: path: ../yarn-unplugged-cache - # TODO: We should use platform input key: ${{ inputs.platform }}-yarn-unplugged-${{ hashFiles('yarn.lock') }} restore-keys: | - - ${{ inputs.platform }}-yarn-unplugged-amd64- + - ${{ inputs.platform }}-yarn-unplugged- - name: Inject cargo cache into docker uses: reproducible-containers/buildkit-cache-dance@v3.1.2 with: cache-map: | { - "../yarn-unplugged-cache": "/tmp/unplugged" + "../yarn-unplugged-cache": { + "target": "/tmp/unplugged", + "id": "unplugged_${{ inputs.platform.replace('linux/', '') }}" + } } skip-extraction: ${{ steps.yarn-cache.outputs.cache-hit }} From 9855b2a3157f138b2cb2a2925960c369f292d9c0 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 14:41:07 +0700 Subject: [PATCH 32/40] ci: second try to remove prefix --- .github/actions/docker/action.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index edabf6fde20..5f655c1aa9f 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -133,6 +133,13 @@ runs: restore-keys: | - ${{ inputs.platform }}-yarn-unplugged- + - name: Set arch + id: arch + uses: actions/github-script@v6 + with: + result-encoding: 'string' + script: return '${{ inputs.platform }}'.replace('linux/', ''); + - name: Inject cargo cache into docker uses: reproducible-containers/buildkit-cache-dance@v3.1.2 with: @@ -140,7 +147,7 @@ runs: { "../yarn-unplugged-cache": { "target": "/tmp/unplugged", - "id": "unplugged_${{ inputs.platform.replace('linux/', '') }}" + "id": "unplugged_${{ steps.arch.outputs.result }}" } } skip-extraction: ${{ steps.yarn-cache.outputs.cache-hit }} From 3d70254fe66c0b2f43ee3a029daf65f0fc3f1c35 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 15:42:25 +0700 Subject: [PATCH 33/40] ci: fix dashmate path --- .github/actions/local-network/action.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/local-network/action.yaml b/.github/actions/local-network/action.yaml index 3c6c4681174..8dd7db9ec77 100644 --- a/.github/actions/local-network/action.yaml +++ b/.github/actions/local-network/action.yaml @@ -36,7 +36,7 @@ runs: bucket: multi-runner-cache-x1xibo9c root: local-network-data path: | - /home/ubuntu/.dashmate + ${{ env.HOME }}/.dashmate **/.env dashmate_volumes_dump key: local-network-volumes/${{ steps.dashmate-fingerprint.outputs.sha }} @@ -73,7 +73,7 @@ runs: bucket: multi-runner-cache-x1xibo9c root: local-network-data path: | - /home/ubuntu/.dashmate + ${{ env.HOME }}/.dashmate **/.env dashmate_volumes_dump key: local-network-volumes/${{ steps.dashmate-fingerprint.outputs.sha }} @@ -92,7 +92,7 @@ runs: # Replace DAPI and Drive images with new org and tag in dashmate config sed -i -E "s/dashpay\/(drive|dapi):[^\"]+/${{ inputs.image_org }}\/\1:${SHA_TAG}/g" /home/ubuntu/.dashmate/config.json - cat /home/ubuntu/.dashmate/config.json + cat ${{ env.HOME }}/.dashmate/config.json - name: Start local network shell: bash From 33ad11bb64cb39237080ddf2ee6972a4e71d2298 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 16:02:43 +0700 Subject: [PATCH 34/40] ci: fix sed --- .github/actions/local-network/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/local-network/action.yaml b/.github/actions/local-network/action.yaml index 8dd7db9ec77..ec78108a1b7 100644 --- a/.github/actions/local-network/action.yaml +++ b/.github/actions/local-network/action.yaml @@ -90,7 +90,7 @@ runs: docker tag ${{ inputs.image_org }}/dashmate-helper:$SHA_TAG dashpay/dashmate-helper:$VERSION # Replace DAPI and Drive images with new org and tag in dashmate config - sed -i -E "s/dashpay\/(drive|dapi):[^\"]+/${{ inputs.image_org }}\/\1:${SHA_TAG}/g" /home/ubuntu/.dashmate/config.json + sed -i -E "s/dashpay\/(drive|dapi):[^\"]+/${{ inputs.image_org }}\/\1:${SHA_TAG}/g" ${{ env.HOME }}/.dashmate/config.json cat ${{ env.HOME }}/.dashmate/config.json From fa5a1884b8d6b57f500512dfbe828e465f7ceaed Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 16:50:28 +0700 Subject: [PATCH 35/40] ci: fix HOME var --- .github/actions/local-network/action.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/actions/local-network/action.yaml b/.github/actions/local-network/action.yaml index ec78108a1b7..42b16723666 100644 --- a/.github/actions/local-network/action.yaml +++ b/.github/actions/local-network/action.yaml @@ -28,6 +28,10 @@ runs: shell: bash run: echo "sha=$(git log -1 --format="%h" -- packages/dashmate)" >> $GITHUB_OUTPUT + - name: Set HOME variable to github context + shell: bash + run: echo "HOME=$HOME" >> $GITHUB_ENV + # TODO: Use upload artifacts action instead - name: Restore local network data id: local-network-data From 633e2ab4a00a67ac7b5405f40aabf0902b62fe12 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 17:22:29 +0700 Subject: [PATCH 36/40] refactor: remove unused params --- packages/dashmate/src/commands/status/masternode.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/dashmate/src/commands/status/masternode.js b/packages/dashmate/src/commands/status/masternode.js index cbc34cd4cab..df4ce999f5a 100644 --- a/packages/dashmate/src/commands/status/masternode.js +++ b/packages/dashmate/src/commands/status/masternode.js @@ -22,8 +22,6 @@ export default class MasternodeStatusCommand extends ConfigBaseCommand { /** * @param {Object} args * @param {Object} flags - * @param {DockerCompose} dockerCompose - * @param {createRpcClient} createRpcClient * @param {Config} config * @param getMasternodeScope getMasternodeScope * @return {Promise} @@ -31,8 +29,6 @@ export default class MasternodeStatusCommand extends ConfigBaseCommand { async runWithDependencies( args, flags, - dockerCompose, - createRpcClient, config, getMasternodeScope, ) { From bd18a7eb315545931efb407e8e7cf207ba1ade49 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 18:07:14 +0700 Subject: [PATCH 37/40] ci: remove CHROME_BIN --- .github/workflows/tests-packges-functional.yml | 1 - .github/workflows/tests-test-suite.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/tests-packges-functional.yml b/.github/workflows/tests-packges-functional.yml index 13cfe492e91..39db41b53f9 100644 --- a/.github/workflows/tests-packges-functional.yml +++ b/.github/workflows/tests-packges-functional.yml @@ -7,7 +7,6 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 15 env: - CHROME_BIN: /usr/bin/brave-browser ECR_HOST: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com steps: - name: Check out repo diff --git a/.github/workflows/tests-test-suite.yml b/.github/workflows/tests-test-suite.yml index 058395c5040..e9107b5e606 100644 --- a/.github/workflows/tests-test-suite.yml +++ b/.github/workflows/tests-test-suite.yml @@ -25,7 +25,6 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 15 env: - CHROME_BIN: /usr/bin/brave-browser ECR_HOST: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com steps: - name: Check out repo From ad83ebbef17363a59c4cf3ac7147d8e3071ad468 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 18:16:42 +0700 Subject: [PATCH 38/40] revert: unnecessary changes --- .github/actions/docker/action.yaml | 24 ++++++++---------------- Dockerfile | 10 ++++++++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index 5f655c1aa9f..baad581dd17 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -22,12 +22,6 @@ inputs: description: User name to use when pushing images to Docker Hub dockerhub_token: description: Docker Hub token to use -# cache_mounts: -# description: Load cache mounts cache -# default: | -# cargo_registry_index -# cargo_registry_cache -# cargo_git cargo_profile: description: Cargo build profile, i.e release or dev default: dev @@ -85,12 +79,12 @@ runs: type=semver,pattern={{version}},value=${{inputs.image_version}},enable=${{ inputs.image_version != '' }} type=sha,format=long,enable=${{ inputs.image_version == '' }} -# - name: Configure docker layer cache -# uses: ./.github/actions/s3-layer-cache-settings -# id: layer_cache_settings -# with: -# name: ${{ inputs.image_name }} -# bucket: ${{ inputs.bucket }} + - name: Configure docker layer cache + uses: ./.github/actions/s3-layer-cache-settings + id: layer_cache_settings + with: + name: ${{ inputs.image_name }} + bucket: ${{ inputs.bucket }} - name: Cargo cache for Docker uses: actions/cache@v4 @@ -171,10 +165,8 @@ runs: SCCACHE_S3_KEY_PREFIX=${{ runner.os }}/sccache AWS_ACCESS_KEY_ID=${{ inputs.aws_access_key_id }} AWS_SECRET_ACCESS_KEY=${{ inputs.aws_secret_access_key }} - #cache-from: ${{ steps.layer_cache_settings.outputs.cache_from }} - cache-from: type=gha - #cache-to: ${{ steps.layer_cache_settings.outputs.cache_to }} - cache-to: type=gha,mode=max + cache-from: ${{ steps.layer_cache_settings.outputs.cache_from }} + cache-to: ${{ steps.layer_cache_settings.outputs.cache_to }} outputs: type=image,name=${{ inputs.image_org }}/${{ inputs.image_name }},push-by-digest=${{ inputs.push_tags != 'true' }},name-canonical=true,push=true # - name: Save Docker mount cache diff --git a/Dockerfile b/Dockerfile index 0f8bfd27202..23766e2f7dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,7 @@ # 2. We add `--config net.git-fetch-with-cli=true` to address ARM build issue, # see https://github.com/rust-lang/cargo/issues/10781#issuecomment-1441071052 # 3. Github Actions have shared networking configured, so we need to set a random +# SCCACHE_SERVER_PORT port to avoid conflicts in case of parallel compilation ARG ALPINE_VERSION=3.18 ARG PROTOC_VERSION=27.3 @@ -117,7 +118,7 @@ ARG RUSTC_WRAPPER ENV RUSTC_WRAPPER=${RUSTC_WRAPPER} # Set args below to use Github Actions cache; see https://github.com/mozilla/sccache/blob/main/docs/GHA.md -ARG SCCACHE_GHA_ENABLED="false" +ARG SCCACHE_GHA_ENABLED ENV SCCACHE_GHA_ENABLED=${SCCACHE_GHA_ENABLED} ARG ACTIONS_CACHE_URL @@ -155,13 +156,13 @@ ENV SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}/${TARGETARCH}/linux-musl WORKDIR /platform -# TODO: Use https://github.com/cargo-bins/cargo-binstall # Install wasm-bindgen-cli in the same profile as other components, to sacrifice some performance & disk space to gain # better build caching RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \ --mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \ --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ + export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ source $HOME/.cargo/env && \ if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ RUSTFLAGS="-C target-feature=-crt-static" \ @@ -205,6 +206,7 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ source $HOME/.cargo/env && \ + export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ cargo chef cook \ --recipe-path recipe.json \ @@ -223,12 +225,14 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ source $HOME/.cargo/env && \ + export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ if [[ "${CARGO_BUILD_PROFILE}" == "release" ]] ; then \ mv .cargo/config-release.toml .cargo/config.toml && \ export OUT_DIRECTORY=release ; \ else \ export FEATURES_FLAG="--features=console,grovedbg" ; \ export OUT_DIRECTORY=debug ; \ + fi && \ if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ cargo build \ @@ -257,6 +261,7 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM --mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \ --mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \ source $HOME/.cargo/env && \ + export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ cargo chef cook \ --recipe-path recipe.json \ @@ -277,6 +282,7 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM cp -R /tmp/unplugged /platform/.yarn/ && \ yarn install --inline-builds && \ cp -R /platform/.yarn/unplugged /tmp/ && \ + export SCCACHE_SERVER_PORT=$((RANDOM+1025)) && \ if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ export SKIP_GRPC_PROTO_BUILD=1 && \ yarn build && \ From a8bd8ff2b22f52a574553e6ecee239e1ad2bd1d8 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 18:21:45 +0700 Subject: [PATCH 39/40] revert: mount cache --- .github/actions/docker/action.yaml | 93 ++++++------------------------ 1 file changed, 19 insertions(+), 74 deletions(-) diff --git a/.github/actions/docker/action.yaml b/.github/actions/docker/action.yaml index baad581dd17..d41ebf4dcfc 100644 --- a/.github/actions/docker/action.yaml +++ b/.github/actions/docker/action.yaml @@ -22,6 +22,12 @@ inputs: description: User name to use when pushing images to Docker Hub dockerhub_token: description: Docker Hub token to use + cache_mounts: + description: Load cache mounts cache + default: | + cargo_registry_index + cargo_registry_cache + cargo_git cargo_profile: description: Cargo build profile, i.e release or dev default: dev @@ -63,12 +69,12 @@ runs: [worker.oci] gc = false -# - name: Load Docker mount cache -# uses: dcginfra/buildkit-cache-dance/inject@s5cmd -# if: ${{ inputs.cache_mounts != '' }} -# with: -# bucket: ${{ inputs.bucket }} -# mounts: ${{ inputs.cache_mounts }} + - name: Load Docker mount cache + uses: dcginfra/buildkit-cache-dance/inject@s5cmd + if: ${{ inputs.cache_mounts != '' }} + with: + bucket: ${{ inputs.bucket }} + mounts: ${{ inputs.cache_mounts }} - name: Set Docker tags and labels from image tag id: docker_meta @@ -86,75 +92,14 @@ runs: name: ${{ inputs.image_name }} bucket: ${{ inputs.bucket }} - - name: Cargo cache for Docker - uses: actions/cache@v4 - id: cargo-cache - with: - path: | - ../cargo-cache-registry-index - ../cargo-cache-registry-cache - ../cargo-cache-git-db - key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} - restore-keys: | - - ${{ runner.os }}-cargo- - - - name: Inject cargo cache into docker - uses: reproducible-containers/buildkit-cache-dance@v3.1.2 - with: - cache-map: | - { - "../cargo-cache-registry-index": { - "target": "/root/.cargo/registry/index", - "id": "cargo_registry_index" - }, - "../cargo-cache-registry-cache": { - "target": "/root/.cargo/registry/cache", - "id": "cargo_registry_cache" - }, - "../cargo-cache-git-db": { - "target": "/root/.cargo/git/db", - "id": "cargo_git" - } - } - skip-extraction: ${{ steps.cargo-cache.outputs.cache-hit }} - - - name: Yarn unplugged cache for Docker - uses: actions/cache@v4 - id: yarn-cache - with: - path: ../yarn-unplugged-cache - key: ${{ inputs.platform }}-yarn-unplugged-${{ hashFiles('yarn.lock') }} - restore-keys: | - - ${{ inputs.platform }}-yarn-unplugged- - - - name: Set arch - id: arch - uses: actions/github-script@v6 - with: - result-encoding: 'string' - script: return '${{ inputs.platform }}'.replace('linux/', ''); - - - name: Inject cargo cache into docker - uses: reproducible-containers/buildkit-cache-dance@v3.1.2 - with: - cache-map: | - { - "../yarn-unplugged-cache": { - "target": "/tmp/unplugged", - "id": "unplugged_${{ steps.arch.outputs.result }}" - } - } - skip-extraction: ${{ steps.yarn-cache.outputs.cache-hit }} - - name: Build and push Docker image ${{ inputs.image }} id: docker_build - uses: docker/build-push-action@v6 + uses: docker/build-push-action@v5 with: context: . builder: ${{ steps.buildx.outputs.name }} target: ${{ inputs.target }} labels: ${{ steps.docker_meta.outputs.labels }} - push: ${{ inputs.push_tags }} tags: ${{ inputs.push_tags == 'true' && steps.docker_meta.outputs.tags || '' }} platforms: ${{ inputs.platform }} build-args: | @@ -169,9 +114,9 @@ runs: cache-to: ${{ steps.layer_cache_settings.outputs.cache_to }} outputs: type=image,name=${{ inputs.image_org }}/${{ inputs.image_name }},push-by-digest=${{ inputs.push_tags != 'true' }},name-canonical=true,push=true -# - name: Save Docker mount cache -# uses: dcginfra/buildkit-cache-dance/extract@s5cmd -# if: ${{ inputs.cache_mounts != '' }} -# with: -# bucket: ${{ inputs.bucket }} -# mounts: ${{ inputs.cache_mounts }} + - name: Save Docker mount cache + uses: dcginfra/buildkit-cache-dance/extract@s5cmd + if: ${{ inputs.cache_mounts != '' }} + with: + bucket: ${{ inputs.bucket }} + mounts: ${{ inputs.cache_mounts }} From ca7017a995134ee4ce1aeee514d72c8667577016 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 13 Nov 2024 18:41:50 +0700 Subject: [PATCH 40/40] ci: fix home dir --- .github/actions/rust/action.yaml | 10 +++++++--- .github/workflows/tests-dashmate.yml | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/actions/rust/action.yaml b/.github/actions/rust/action.yaml index 88540070133..c22923a221b 100644 --- a/.github/actions/rust/action.yaml +++ b/.github/actions/rust/action.yaml @@ -95,6 +95,10 @@ runs: shell: bash run: echo "key=$(echo '${{ github.ref_name }}' | sha256sum | cut -d ' ' -f1)" >> $GITHUB_OUTPUT + - name: Set HOME variable to github context + shell: bash + run: echo "HOME=$HOME" >> $GITHUB_ENV + - name: Cache cargo registry (S3 bucket cache) uses: strophy/actions-cache@opendal-update if: inputs.cache == 'true' @@ -102,9 +106,9 @@ runs: bucket: multi-runner-cache-x1xibo9c root: actions-cache path: | - /home/ubuntu/.cargo/registry/index - /home/ubuntu/.cargo/registry/cache - /home/ubuntu/.cargo/git + ${{ env.HOME }}/.cargo/registry/index + ${{ env.HOME }}/.cargo/registry/cache + ${{ env.HOME }}/.cargo/git key: ${{ runner.os }}/cargo/registry/${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}/cargo/registry/${{ hashFiles('**/Cargo.lock') }} diff --git a/.github/workflows/tests-dashmate.yml b/.github/workflows/tests-dashmate.yml index 557c755af41..6e1b527aa06 100644 --- a/.github/workflows/tests-dashmate.yml +++ b/.github/workflows/tests-dashmate.yml @@ -84,6 +84,10 @@ jobs: run: echo "sha=$(git log -1 --format="%h" -- packages/dashmate)" >> $GITHUB_OUTPUT if: inputs.restore_local_network_data == true + - name: Set HOME variable to github context + shell: bash + run: echo "HOME=$HOME" >> $GITHUB_ENV + - name: Use test suite local network data to speed up dashmate local network tests id: local-network-data uses: strophy/actions-cache/restore@opendal-update @@ -91,7 +95,7 @@ jobs: bucket: multi-runner-cache-x1xibo9c root: local-network-data path: | - /home/ubuntu/.dashmate + ${{ env.HOME }}/.dashmate dashmate_volumes_dump key: local-network-volumes/${{ steps.dashmate-fingerprint.outputs.sha }} if: inputs.restore_local_network_data == true @@ -105,7 +109,7 @@ jobs: env: DEBUG: 1 DASHMATE_E2E_TESTS_SKIP_IMAGE_BUILD: true - DASHMATE_E2E_TESTS_LOCAL_HOMEDIR: /home/ubuntu/.dashmate + DASHMATE_E2E_TESTS_LOCAL_HOMEDIR: ${{ env.HOME }}/.dashmate if: steps.local-network-data.outputs.cache-hit == 'true' - name: Run tests without cache