Skip to content

Commit

Permalink
Merge conflict fixes, bidding wireup
Browse files Browse the repository at this point in the history
  • Loading branch information
EdHastingsCasperAssociation committed Mar 1, 2024
1 parent e1661a1 commit 6bae75d
Show file tree
Hide file tree
Showing 20 changed files with 804 additions and 139 deletions.
185 changes: 128 additions & 57 deletions node/src/components/contract_runtime/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use casper_execution_engine::engine_state::{
use casper_storage::{
block_store::types::ApprovalsHashes,
data_access_layer::{
BlockRewardsRequest, BlockRewardsResult, DataAccessLayer, EraValidatorsRequest,
EraValidatorsResult, EvictItem, FeeRequest, FeeResult, FlushRequest, PruneRequest,
PruneResult, StepRequest, StepResult, TransferRequest,
AuctionMethod, BiddingRequest, BiddingResult, BlockRewardsRequest, BlockRewardsResult,
DataAccessLayer, EraValidatorsRequest, EraValidatorsResult, EvictItem, FeeRequest,
FeeResult, FlushRequest, PruneRequest, PruneResult, StepRequest, StepResult,
TransferRequest, TransferResult,
},
global_state::{
error::Error as GlobalStateError,
Expand All @@ -28,8 +29,8 @@ use casper_types::{
binary_port::SpeculativeExecutionResult,
bytesrepr::{self, ToBytes, U32_SERIALIZED_LENGTH},
contract_messages::Messages,
execution::{Effects, ExecutionResult, Transform, TransformKind},
BlockV2, CLValue, Chainspec, ChecksumRegistry, DeployHash, Digest, EraEndV2, EraId, Gas, Key,
execution::{Effects, ExecutionResult, ExecutionResultV2, Transform, TransformKind},
BlockV2, CLValue, Chainspec, ChecksumRegistry, DeployHash, Digest, EraEndV2, EraId, Key,
ProtocolVersion, PublicKey, Transaction, TransactionApprovalsHash, U512,
};

Expand Down Expand Up @@ -76,7 +77,7 @@ pub fn execute_finalized_block(
let parent_seed = execution_pre_state.parent_seed();

let mut state_root_hash = pre_state_root_hash;
let mut execution_results: Vec<ExecutionArtifact> =
let mut execution_artifacts: Vec<ExecutionArtifact> =
Vec::with_capacity(executable_block.transactions.len());
let block_time = executable_block.timestamp.millis();
let start = Instant::now();
Expand Down Expand Up @@ -107,14 +108,16 @@ pub fn execute_finalized_block(
}
FeeResult::Failure(fer) => return Err(BlockExecutionError::DistributeFees(fer)),
FeeResult::Success {
post_state_hash, ..
//transfers: fee_transfers,
post_state_hash,
..
} => {
state_root_hash = post_state_hash;
//transfers.extend(fee_transfers);
// TODO: looks like effects & transfer records are associated with the ExecutionResult struct
// which assumes they were caused by a deploy. however, systemic operations produce effects
// and transfer records also.
state_root_hash = post_state_hash;
// TODO: looks like effects & transfer records are associated with the
// ExecutionResult struct which assumes they were caused by a
// deploy. however, systemic operations produce effects and transfer
// records also.
}
}
}
Expand Down Expand Up @@ -148,52 +151,120 @@ pub fn execute_finalized_block(
}

for transaction in executable_block.transactions {
let (deploy_hash, deploy) = match transaction {
Transaction::Deploy(deploy) => {
let deploy_hash = *deploy.hash();
if deploy.is_transfer() {
// native transfers are routed to the data provider
let authorization_keys = deploy
.approvals()
.iter()
.map(|approval| approval.signer().to_account_hash())
.collect();
let transfer_req = TransferRequest::with_runtime_args(
native_runtime_config.clone(),
state_root_hash,
block_time,
protocol_version,
deploy_hash.into(),
deploy.header().account().to_account_hash(),
authorization_keys,
deploy.session().args().clone(),
U512::zero(), /* <-- this should be from chainspec cost table */
let transaction_hash = transaction.hash();
if transaction.is_native_mint() {
// native transfers are routed to the data provider
let authorization_keys = transaction.authorization_keys();
let transfer_req = TransferRequest::with_runtime_args(
native_runtime_config.clone(),
state_root_hash,
block_time,
protocol_version,
transaction_hash,
transaction.initiator_addr().account_hash(),
authorization_keys,
transaction.session_args().clone(),
U512::zero(), /* <-- this should be from chainspec cost table */
);
//NOTE: native mint interactions auto-commit
let transfer_result = data_access_layer.transfer(transfer_req);
trace!(
?transaction_hash,
?transfer_result,
"native transfer result"
);
match transfer_result {
TransferResult::RootNotFound => {
return Err(BlockExecutionError::RootNotFound(state_root_hash));
}
TransferResult::Failure(transfer_error) => {
let artifact = ExecutionArtifact::new(
transaction_hash,
transaction.header(),
ExecutionResult::V2(ExecutionResultV2::Failure {
effects: Effects::new(),
cost: U512::zero(),
transfers: vec![],
error_message: format!("{:?}", transfer_error),
}),
Messages::default(),
);
// native transfer auto-commits
let transfer_result = data_access_layer.transfer(transfer_req);
trace!(?deploy_hash, ?transfer_result, "native transfer result");
match EngineExecutionResult::from_transfer_result(
transfer_result,
Gas::new(U512::zero()),
) {
Err(_) => return Err(BlockExecutionError::RootNotFound(state_root_hash)),
Ok(exec_result) => {
let ExecutionResultAndMessages {
execution_result,
messages,
} = ExecutionResultAndMessages::from(exec_result);
let versioned_execution_result =
ExecutionResult::from(execution_result);
execution_results.push(ExecutionArtifact::new(
deploy_hash,
deploy.header().clone(),
versioned_execution_result,
messages,
));
}
}
execution_artifacts.push(artifact);
debug!(%transfer_error);
// a failure does not auto commit
continue;
}
TransferResult::Success {
post_state_hash,
transfers,
..
} => {
// ideally we should be doing something with the transfer records and effects,
// but currently this is auto-commit and if we include the effects in the
// collection they will get double-committed. there's also
// the problem that the execution results type needs to be
// made more expressive / flexible. effects? transfers?
state_root_hash = post_state_hash;
let artifact = ExecutionArtifact::new(
transaction_hash,
transaction.header(),
ExecutionResult::V2(ExecutionResultV2::Success {
effects: Effects::new(), // auto commit
cost: U512::zero(),
transfers,
}),
Messages::default(),
);
execution_artifacts.push(artifact);
}
}
continue;
}
if transaction.is_native_auction() {
let args = transaction.session_args();
let entry_point = transaction.entry_point();
let auction_method = match AuctionMethod::from_parts(entry_point, args, chainspec) {
Ok(auction_method) => auction_method,
Err(_) => {
error!(%transaction_hash, "failed to resolve auction method");
continue; // skip to next record
}
};
let authorization_keys = transaction.authorization_keys();
let bidding_req = BiddingRequest::new(
native_runtime_config.clone(),
state_root_hash,
block_time,
protocol_version,
transaction_hash,
transaction.initiator_addr().account_hash(),
authorization_keys,
auction_method,
);

//NOTE: native mint interactions auto-commit
let bidding_result = data_access_layer.bidding(bidding_req);
trace!(?transaction_hash, ?bidding_result, "native auction result");
match bidding_result {
BiddingResult::RootNotFound => {
return Err(BlockExecutionError::RootNotFound(state_root_hash))
}
BiddingResult::Success {
post_state_hash, ..
} => {
// we need a way to capture the effects from this without double committing
state_root_hash = post_state_hash;
}
BiddingResult::Failure(tce) => {
debug!(%tce);
continue;
}
}
}

let (deploy_hash, deploy) = match transaction {
Transaction::Deploy(deploy) => {
let deploy_hash = *deploy.hash();
(deploy_hash, deploy)
}
Transaction::V1(_) => continue,
Expand Down Expand Up @@ -224,7 +295,7 @@ pub fn execute_finalized_block(
deploy_hash,
exec_result,
)?;
execution_results.push(ExecutionArtifact::new(
execution_artifacts.push(ExecutionArtifact::deploy(
deploy_hash,
deploy_header,
execution_result,
Expand All @@ -241,7 +312,7 @@ pub fn execute_finalized_block(

// Write the deploy approvals' and execution results' checksums to global state.
let execution_results_checksum = compute_execution_results_checksum(
execution_results
execution_artifacts
.iter()
.map(|artifact| &artifact.execution_result),
)?;
Expand Down Expand Up @@ -477,7 +548,7 @@ pub fn execute_finalized_block(
Ok(BlockAndExecutionResults {
block,
approvals_hashes,
execution_results,
execution_results: execution_artifacts,
maybe_step_effects_and_upcoming_era_validators,
})
}
Expand Down
42 changes: 36 additions & 6 deletions node/src/components/contract_runtime/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use casper_types::{
contract_messages::Messages,
execution::{Effects, ExecutionResult},
BlockHash, BlockHeaderV2, BlockV2, DeployHash, DeployHeader, Digest, EraId, ProtocolVersion,
PublicKey, Timestamp, U512,
PublicKey, Timestamp, TransactionHash, TransactionHeader, TransactionV1Hash,
TransactionV1Header, U512,
};

/// Request for validator weights for a specific era.
Expand Down Expand Up @@ -64,22 +65,51 @@ pub(crate) struct StepEffectsAndUpcomingEraValidators {

#[derive(Clone, Debug, DataSize, PartialEq, Eq, Serialize)]
pub(crate) struct ExecutionArtifact {
pub(crate) deploy_hash: DeployHash,
pub(crate) deploy_header: DeployHeader,
pub(crate) transaction_hash: TransactionHash,
pub(crate) header: TransactionHeader,
pub(crate) execution_result: ExecutionResult,
pub(crate) messages: Messages,
}

impl ExecutionArtifact {
pub(crate) fn new(
transaction_hash: TransactionHash,
header: TransactionHeader,
execution_result: ExecutionResult,
messages: Messages,
) -> Self {
Self {
transaction_hash,
header,
execution_result,
messages,
}
}

pub(crate) fn deploy(
deploy_hash: DeployHash,
deploy_header: DeployHeader,
header: DeployHeader,
execution_result: ExecutionResult,
messages: Messages,
) -> Self {
Self {
transaction_hash: TransactionHash::Deploy(deploy_hash),
header: TransactionHeader::Deploy(header),
execution_result,
messages,
}
}

#[allow(unused)]
pub(crate) fn v1(
transaction_hash: TransactionV1Hash,
header: TransactionV1Header,
execution_result: ExecutionResult,
messages: Messages,
) -> Self {
Self {
deploy_hash,
deploy_header,
transaction_hash: TransactionHash::V1(transaction_hash),
header: TransactionHeader::V1(header),
execution_result,
messages,
}
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/contract_runtime/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub(super) async fn exec_or_requeue<REv>(
let execution_results_map: HashMap<_, _> = execution_results
.iter()
.cloned()
.map(|artifact| (artifact.deploy_hash.into(), artifact.execution_result))
.map(|artifact| (artifact.transaction_hash, artifact.execution_result))
.collect();
if meta_block_state.register_as_stored().was_updated() {
effect_builder
Expand Down
3 changes: 2 additions & 1 deletion node/src/components/transaction_acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ impl TransactionAcceptor {
| TransactionEntryPoint::WithdrawBid
| TransactionEntryPoint::Delegate
| TransactionEntryPoint::Undelegate
| TransactionEntryPoint::Redelegate => None,
| TransactionEntryPoint::Redelegate
| TransactionEntryPoint::ActivateBid => None,
},
};

Expand Down
8 changes: 3 additions & 5 deletions node/src/reactor/main_reactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use casper_types::{
binary_port::{LastProgress, NetworkName, Uptime},
Block, BlockHash, BlockV2, Chainspec, ChainspecRawBytes, DeployId, EraId, FinalitySignature,
FinalitySignatureV2, PublicKey, ReactorState, TimeDiff, Timestamp, Transaction,
TransactionHash, TransactionHeader, TransactionId, U512,
TransactionHash, TransactionId, U512,
};

#[cfg(test)]
Expand Down Expand Up @@ -1651,10 +1651,8 @@ impl MainReactor {
MetaBlock::Forward(fwd_meta_block) => {
for exec_artifact in fwd_meta_block.execution_results.iter() {
let event = event_stream_server::Event::TransactionProcessed {
transaction_hash: TransactionHash::Deploy(exec_artifact.deploy_hash),
transaction_header: Box::new(TransactionHeader::Deploy(
exec_artifact.deploy_header.clone(),
)),
transaction_hash: exec_artifact.transaction_hash,
transaction_header: Box::new(exec_artifact.header.clone()),
block_hash: *fwd_meta_block.block.hash(),
execution_result: Box::new(exec_artifact.execution_result.clone()),
messages: exec_artifact.messages.clone(),
Expand Down
10 changes: 5 additions & 5 deletions node/src/types/block/meta_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod tests {

let block = Arc::new(TestBlockBuilder::new().build(rng));
let deploy = Deploy::random(rng);
let execution_results = vec![ExecutionArtifact::new(
let execution_results = vec![ExecutionArtifact::deploy(
*deploy.hash(),
deploy.take_header(),
ExecutionResult::from(ExecutionResultV2::random(rng)),
Expand Down Expand Up @@ -236,7 +236,7 @@ mod tests {

let block = Arc::new(TestBlockBuilder::new().build(rng));
let deploy = Deploy::random(rng);
let execution_results = vec![ExecutionArtifact::new(
let execution_results = vec![ExecutionArtifact::deploy(
*deploy.hash(),
deploy.take_header(),
ExecutionResult::from(ExecutionResultV2::random(rng)),
Expand Down Expand Up @@ -274,7 +274,7 @@ mod tests {
.build(rng),
);
let deploy = Deploy::random(rng);
let execution_results = vec![ExecutionArtifact::new(
let execution_results = vec![ExecutionArtifact::deploy(
*deploy.hash(),
deploy.take_header(),
ExecutionResult::from(ExecutionResultV2::random(rng)),
Expand Down Expand Up @@ -307,14 +307,14 @@ mod tests {

let block = Arc::new(TestBlockBuilder::new().build(rng));
let deploy1 = Deploy::random(rng);
let execution_results1 = vec![ExecutionArtifact::new(
let execution_results1 = vec![ExecutionArtifact::deploy(
*deploy1.hash(),
deploy1.take_header(),
ExecutionResult::from(ExecutionResultV2::random(rng)),
Vec::new(),
)];
let deploy2 = Deploy::random(rng);
let execution_results2 = vec![ExecutionArtifact::new(
let execution_results2 = vec![ExecutionArtifact::deploy(
*deploy2.hash(),
deploy2.take_header(),
ExecutionResult::from(ExecutionResultV2::random(rng)),
Expand Down
Loading

0 comments on commit 6bae75d

Please sign in to comment.