Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Oct 15, 2021
1 parent f3dcb32 commit 15ad914
Show file tree
Hide file tree
Showing 36 changed files with 1,318 additions and 1,440 deletions.
12 changes: 0 additions & 12 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion consensus/src/consensus/inner/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl ConsensusInner {
// no blocks present/genesis situation
if canon.is_empty() {
// no blocks
let hash = self.public.genesis_block.header.hash();
let hash = self.public.genesis_block.block_hash();
let block = self.public.genesis_block.clone();
self.storage.insert_block(&block).await?;

Expand Down
28 changes: 14 additions & 14 deletions consensus/src/consensus/inner/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl ConsensusInner {
pub(super) async fn receive_block(&mut self, block: &Block<N>) -> Result<(), ConsensusError> {
self.storage.insert_block(block).await?;

let hash = block.header.hash();
let hash = block.block_hash();
match self.try_commit_block(&hash, block).await {
Err(ConsensusError::InvalidBlock(hash)) => {
self.storage.delete_block(&hash).await?;
Expand All @@ -44,7 +44,7 @@ impl ConsensusInner {
pub(super) async fn try_commit_block(&mut self, hash: &Digest, block: &Block<N>) -> Result<(), ConsensusError> {
let canon = self.storage.canon().await?;

match self.storage.get_block_state(&block.header.previous_block_hash).await? {
match self.storage.get_block_state(&block.previous_block_hash()).await? {
BlockStatus::Committed(n) if n == canon.block_height => {
debug!("Processing a block that is on canon chain. Height {} -> {}", n, n + 1);
metrics::gauge!(metrics::blocks::HEIGHT, n as f64 + 1.0);
Expand Down Expand Up @@ -108,7 +108,7 @@ impl ConsensusInner {
self.verify_and_commit_block(hash, block).await?;
} else {
let new_block = self.storage.get_block(block_hash).await?;
self.verify_and_commit_block(&new_block.header.hash(), &new_block)
self.verify_and_commit_block(&new_block.block_hash(), &new_block)
.await?;
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ impl ConsensusInner {
self.commit_block(hash, block).await?;

// 3. Remove transactions from the mempool
for transaction in block.transactions.iter() {
for transaction in block.transactions().iter() {
self.memory_pool.remove(&transaction.id.into())?;
}

Expand All @@ -178,15 +178,15 @@ impl ConsensusInner {
pub(super) async fn verify_block(&mut self, block: &Block<N>) -> Result<bool, ConsensusError> {
let canon = self.storage.canon().await?;
// Verify the block header
if block.header.previous_block_hash != canon.hash {
if block.previous_block_hash() != canon.hash {
return Err(anyhow!("attempted to commit a block that wasn't a direct child of tip of canon").into());
}

// Verify block amounts and check that there is a single coinbase transaction
let mut coinbase_transaction_count: i32 = 0;
let mut total_value_balance = AleoAmount::ZERO;

for transaction in block.transactions.iter() {
for transaction in block.transactions().iter() {
let value_balance = transaction.value_balance;

if value_balance.is_negative() {
Expand Down Expand Up @@ -214,9 +214,9 @@ impl ConsensusInner {
return Ok(false);
}

let block_header = block.header.clone();
let block_header = block.header().clone();
let parent_header = self.storage.get_block_header(&canon.hash).await?;
let transaction_ids: Vec<[u8; 32]> = block.transactions.iter().map(|x| x.id).collect();
let transaction_ids: Vec<[u8; 32]> = block.transactions().iter().map(|x| x.id).collect();
let consensus = self.public.clone();

let verification_result = task::spawn_blocking(move || {
Expand All @@ -240,7 +240,7 @@ impl ConsensusInner {
}

// Check that all the transaction proofs verify
self.verify_transactions(block.transactions.clone()).await
self.verify_transactions(block.transactions().clone()).await
}

async fn resolve_recommit_taint(
Expand Down Expand Up @@ -307,9 +307,9 @@ impl ConsensusInner {
let resolved_digests = self
.resolve_recommit_taint(&mut commitments, &mut serial_numbers, &mut memos)
.await?;
for transaction in block.transactions.iter() {
for transaction in block.transactions().iter() {
commitments.extend_from_slice(&transaction.new_commitments[..]);
serial_numbers.extend_from_slice(&transaction.old_serial_numbers[..]);
serial_numbers.extend_from_slice(&transaction.serial_numbers[..]);
memos.push(transaction.memorandum.clone());
}

Expand Down Expand Up @@ -391,10 +391,10 @@ impl ConsensusInner {
let mut memos = vec![];
debug!("decommited {} blocks", decommited_blocks.len());
for block in decommited_blocks.into_iter().rev() {
debug!("ledger: rolling back block {}", block.header.hash());
for transaction in block.transactions.iter() {
debug!("ledger: rolling back block {}", block.block_hash());
for transaction in block.transactions().iter() {
commitments.extend_from_slice(&transaction.new_commitments[..]);
serial_numbers.extend_from_slice(&transaction.old_serial_numbers[..]);
serial_numbers.extend_from_slice(&transaction.serial_numbers[..]);
memos.push(transaction.memorandum.clone());
}
}
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/consensus/inner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ impl ConsensusInner {
) -> Result<Option<Digest>, ConsensusError> {
let transaction_id: Digest = transaction.id.into();

if has_duplicates(&transaction.old_serial_numbers)
if has_duplicates(&transaction.serial_numbers)
|| has_duplicates(&transaction.new_commitments)
|| self.memory_pool.transactions.contains_key(&transaction_id)
{
return Ok(None);
}

for sn in &transaction.old_serial_numbers {
for sn in &transaction.serial_numbers {
if self.ledger.contains_serial(sn) || self.memory_pool.serial_numbers.contains(sn) {
return Ok(None);
}
Expand All @@ -78,7 +78,7 @@ impl ConsensusInner {
return Ok(None);
}

for sn in &transaction.old_serial_numbers {
for sn in &transaction.serial_numbers {
self.memory_pool.serial_numbers.insert(sn.clone());
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/src/memory_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl MemoryPool {
panic!("missing commitment from memory pool during removal");
}
}
for serial in &entry.transaction.old_serial_numbers {
for serial in &entry.transaction.serial_numbers {
if !self.serial_numbers.remove(serial) {
panic!("missing serial from memory pool during removal");
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl MineContext {
if self.consensus.parameters.network_id != transaction.network {
return Err(ConsensusError::ConflictingNetworkId(
self.consensus.parameters.network_id.id(),
transaction.network.id(),
transaction.network_id(),
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion network/src/sync/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl MinerInstance {

metrics::increment_counter!(metrics::blocks::MINED);

info!("Mined a new block: {:?}", hex::encode(block.header.hash().0));
info!("Mined a new block: {:?}", hex::encode(block.block_hash().0));

let serialized_block = block.serialize();
let node_clone = self.node.clone();
Expand Down
8 changes: 2 additions & 6 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ Returns information about a transaction from serialized transaction bytes.
|:-----------------------:|:------:|:----------------------------------------- |
| `txid` | string | The transaction id |
| `size` | number | The size of the transaction in bytes |
| `old_serial_numbers` | array | The list of old record serial numbers |
| `serial_numbers` | array | The list of old record serial numbers |
| `new_commitments` | array | The list of new record commitments |
| `memo` | string | The transaction memo |
| `network_id` | number | The transaction network id |
| `digest` | string | The merkle tree digest |
| `transaction_proof` | string | The transaction zero knowledge proof |
| `program_commitment` | string | The program verification key commitment |
| `local_data_root` | string | The local data root |
| `value_balance` | number | The transaction value balance |
| `signatures` | array | The list of transaction signatures |
| `encrypted_records` | array | The list of new encrypted records |
Expand Down Expand Up @@ -371,14 +369,12 @@ Returns information about a transaction from a transaction id.
|:-----------------------:|:------:|:---------------------------------------- |
| `txid` | string | The transaction id |
| `size` | number | The size of the transaction in bytes |
| `old_serial_numbers` | array | The list of old record serial numbers |
| `serial_numbers` | array | The list of old record serial numbers |
| `new_commitments` | array | The list of new record commitments |
| `memo` | string | The transaction memo |
| `network_id` | number | The transaction network id |
| `digest` | string | The merkle tree digest |
| `transaction_proof` | string | The transaction zero knowledge proof |
| `program_commitment` | string | The program verification key commitment |
| `local_data_root` | string | The local data root |
| `value_balance` | number | The transaction value balance |
| `signatures` | array | The list of transaction signatures |
| `encrypted_records` | array | The list of new encrypted records |
Expand Down
4 changes: 1 addition & 3 deletions rpc/documentation/public_endpoints/decoderawtransaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ Returns information about a transaction from serialized transaction bytes.
|:-----------------------:|:------:|:----------------------------------------- |
| `txid` | string | The transaction id |
| `size` | number | The size of the transaction in bytes |
| `old_serial_numbers` | array | The list of old record serial numbers |
| `serial_numbers` | array | The list of old record serial numbers |
| `new_commitments` | array | The list of new record commitments |
| `memo` | string | The transaction memo |
| `network_id` | number | The transaction network id |
| `digest` | string | The merkle tree digest |
| `transaction_proof` | string | The transaction zero knowledge proof |
| `program_commitment` | string | The program verification key commitment |
| `local_data_root` | string | The local data root |
| `value_balance` | number | The transaction value balance |
| `signatures` | array | The list of transaction signatures |
| `encrypted_records` | array | The list of new encrypted records |
Expand Down
4 changes: 1 addition & 3 deletions rpc/documentation/public_endpoints/gettransactioninfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ Returns information about a transaction from a transaction id.
|:-----------------------:|:------:|:---------------------------------------- |
| `txid` | string | The transaction id |
| `size` | number | The size of the transaction in bytes |
| `old_serial_numbers` | array | The list of old record serial numbers |
| `serial_numbers` | array | The list of old record serial numbers |
| `new_commitments` | array | The list of new record commitments |
| `memo` | string | The transaction memo |
| `network_id` | number | The transaction network id |
| `digest` | string | The merkle tree digest |
| `transaction_proof` | string | The transaction zero knowledge proof |
| `program_commitment` | string | The program verification key commitment |
| `local_data_root` | string | The local data root |
| `value_balance` | number | The transaction value balance |
| `signatures` | array | The list of transaction signatures |
| `encrypted_records` | array | The list of new encrypted records |
Expand Down
30 changes: 14 additions & 16 deletions rpc/src/rpc_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ impl RpcFunctions for RpcImpl {
};

let block = self.storage.get_block(&block_header_hash).await?;
let mut transactions = Vec::with_capacity(block.transactions.len());
let mut transactions = Vec::with_capacity(block.transactions().len());

for transaction in block.transactions.iter() {
for transaction in block.transactions().iter() {
transactions.push(hex::encode(&transaction.id));
}

Expand All @@ -255,13 +255,13 @@ impl RpcFunctions for RpcImpl {
height: height.map(|x| x as u32),
confirmations: confirmations as u32,
size: block.serialize().len(), // todo: we should not do this
previous_block_hash: block.header.previous_block_hash.to_string(),
merkle_root: block.header.merkle_root_hash.to_string(),
pedersen_merkle_root_hash: block.header.pedersen_merkle_root_hash.to_string(),
proof: block.header.proof.to_string(),
time: block.header.time,
difficulty_target: block.header.difficulty_target,
nonce: block.header.nonce,
previous_block_hash: block.previous_block_hash().to_string(),
merkle_root: block.header().merkle_root_hash.to_string(),
pedersen_merkle_root_hash: block.header().pedersen_merkle_root_hash.to_string(),
proof: block.header().proof.to_string(),
time: block.header().time,
difficulty_target: block.header().difficulty_target,
nonce: block.header().nonce,
transactions,
})
}
Expand Down Expand Up @@ -307,12 +307,12 @@ impl RpcFunctions for RpcImpl {
let transaction_bytes = hex::decode(transaction_bytes)?;
let transaction = Testnet1Transaction::read_le(&transaction_bytes[..])?;

let mut old_serial_numbers = Vec::with_capacity(transaction.old_serial_numbers().len());
let mut serial_numbers = Vec::with_capacity(transaction.serial_numbers().len());

for sn in transaction.old_serial_numbers() {
for sn in transaction.serial_numbers() {
let mut serial_number: Vec<u8> = vec![];
CanonicalSerialize::serialize(sn, &mut serial_number).unwrap();
old_serial_numbers.push(hex::encode(serial_number));
serial_numbers.push(hex::encode(serial_number));
}

let mut new_commitments = Vec::with_capacity(transaction.new_commitments().len());
Expand Down Expand Up @@ -349,14 +349,12 @@ impl RpcFunctions for RpcImpl {
Ok(TransactionInfo {
txid: hex::encode(&transaction_id),
size: transaction_bytes.len(),
old_serial_numbers,
serial_numbers,
new_commitments,
memo,
network_id: transaction.network.id(),
network_id: transaction.network_id(),
digest: hex::encode(to_bytes_le![transaction.ledger_digest]?),
transaction_proof: hex::encode(to_bytes_le![transaction.transaction_proof]?),
program_commitment: hex::encode(to_bytes_le![transaction.program_commitment]?),
local_data_root: hex::encode(to_bytes_le![transaction.local_data_root]?),
value_balance: transaction.value_balance.0,
signatures,
encrypted_records,
Expand Down
Loading

0 comments on commit 15ad914

Please sign in to comment.