Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel client #282

Merged
merged 41 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d8b8354
ChatGPT assisted draft
maciejka Oct 16, 2024
1f8e527
fixes, logging
maciejka Oct 17, 2024
910dd7a
fmt
maciejka Oct 17, 2024
ee4d7ae
fix cached utxo assert
maciejka Oct 18, 2024
3d030e6
fix cached utxo assert 2
maciejka Oct 18, 2024
7269421
fix cached utxo assert 3
maciejka Oct 18, 2024
3f2910b
ChatGPT assisted draft
maciejka Oct 16, 2024
767306d
fixes, logging
maciejka Oct 17, 2024
e687e41
fmt
maciejka Oct 17, 2024
5c7636d
fix cached utxo assert
maciejka Oct 18, 2024
eab6941
fix cached utxo assert 2
maciejka Oct 18, 2024
1cd590d
fix cached utxo assert 3
maciejka Oct 18, 2024
4cd4d12
debug
maciejka Oct 18, 2024
ccb858c
Merge branch 'mk/parallel_client' of github.com:keep-starknet-strange…
maciejka Oct 18, 2024
75f407c
fixes
maciejka Oct 18, 2024
a30f234
fix loggging
maciejka Oct 18, 2024
9672c5c
fix
maciejka Oct 18, 2024
16561eb
log to file
maciejka Oct 18, 2024
348d1b8
remove wait timeout
maciejka Oct 19, 2024
67f91e1
client2 fixes
maciejka Oct 21, 2024
7e3f5c3
Script adjustments
maciejka Oct 21, 2024
e426dda
fmt
maciejka Oct 21, 2024
11f6aaa
Merge branch 'mk/parallel_client' of github.com:keep-starknet-strange…
maciejka Oct 21, 2024
5cc9cc2
fmt
maciejka Oct 21, 2024
3a3f4ad
fixes
maciejka Oct 21, 2024
832b541
fmt
maciejka Oct 21, 2024
11557e9
Merge remote-tracking branch 'origin/main' into mk/parallel_client
maciejka Oct 21, 2024
d87d425
fix mtp check?
maciejka Oct 21, 2024
793d7ab
fix tests
maciejka Oct 21, 2024
1ae0f0b
fmt
maciejka Oct 21, 2024
52b77bb
fix mtp in utxo data
maciejka Oct 23, 2024
f1481f9
shebangs
maciejka Oct 23, 2024
a961c1b
a comment
maciejka Oct 23, 2024
2170c4e
fmt
maciejka Oct 23, 2024
08d4a76
add maxweight arg
maciejka Oct 23, 2024
80388ac
fmt
maciejka Oct 23, 2024
4865246
fix output maturity bug
maciejka Oct 23, 2024
d4527c4
handle OOM situations
maciejka Oct 23, 2024
cb6da9a
fmt
maciejka Oct 23, 2024
38f40e0
client log file rotation
maciejka Oct 25, 2024
c582dba
fmt
maciejka Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ __pycache__

corelib
*.txt
client.errors.log
2 changes: 1 addition & 1 deletion Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = [
[[package]]
name = "ripemd160"
version = "0.1.0"
source = "git+https://github.com/j1mbo64/ripemd160_cairo.git#cdc5ab58b0acc64db87e0b03851fb18213977dc8"
source = "git+https://github.com/j1mbo64/ripemd160_cairo.git#b56e8f3135f2e30bcf3e035a72b7bc4d0f4a9e45"

[[package]]
name = "sha1"
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct UtreexoArgs {
/// Panics in case of a validation error or chain state mismatch.
/// Prints result to the stdout.
pub(crate) fn main(mut arguments: Span<felt252>, execute_script: bool) {
println!("Running integration test... ");
let mut gas_before = get_available_gas();

let Args { mut chain_state, blocks, expected_chain_state, utreexo_args } = Serde::deserialize(
Expand Down
90 changes: 90 additions & 0 deletions packages/client/tests/data/full_32635.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"chain_state": {
"block_height": 32635,
"total_work": "140471204149688",
"best_block_hash": "00000000cebd072bf3f8e4c0c2476af02ae14ee14e5efa531150c2c0727b58a4",
"current_target": "22791060871177364286867400663010583169263383106957897897309909286912",
"epoch_start_time": 1262153464,
"prev_timestamps": [
1262394898,
1262395265,
1262395666,
1262395855,
1262407030,
1262407185,
1262401695,
1262408047,
1262404445,
1262401297,
1262406394
]
},
"blocks": [
{
"header": {
"version": 1,
"time": 1262404288,
"bits": 486594666,
"nonce": 248271393
},
"data": {
"variant_id": 1,
"transactions": [
{
"version": 1,
"is_segwit": false,
"inputs": [
{
"script": "0x046ad8001d02bf01",
"sequence": 4294967295,
"previous_output": {
"txid": "0000000000000000000000000000000000000000000000000000000000000000",
"vout": 4294967295,
"data": {
"value": 0,
"pk_script": "0x",
"cached": false
},
"block_height": 0,
"median_time_past": 0,
"is_coinbase": false
},
"witness": [
"0x0000000000000000000000000000000000000000000000000000000000000000"
]
}
],
"outputs": [
{
"value": 5000000000,
"pk_script": "0x41047c35e7c098d1c3ec1f195b8cea423d038e3f9fbd3fe236142bb106f1c394c1c86445e9d42cb989f8c3ee869567795903524e23c5b7c157027300ec3c46c53ebeac",
"cached": false
}
],
"lock_time": 0
}
]
}
}
],
"expected": {
"block_height": 32636,
"total_work": "140476284742026",
"best_block_hash": "0000000073bdd2eab743b2355838c87d4e452b5b36d5700fd582b10079de27ce",
"current_target": "22791060871177364286867400663010583169263383106957897897309909286912",
"epoch_start_time": 1262153464,
"prev_timestamps": [
1262395265,
1262395666,
1262395855,
1262407030,
1262407185,
1262401695,
1262408047,
1262404445,
1262401297,
1262406394,
1262404288
]
}
}
90 changes: 90 additions & 0 deletions packages/client/tests/data/full_91721.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"chain_state": {
"block_height": 91721,
"total_work": "120749717356492800",
"best_block_hash": "00000000000a30044feb1a9010445c5b6d4cdc3f32ca747cff2525c32976ba42",
"current_target": "5942996718418989293499865695368015163438891473576991811912597504",
"epoch_start_time": 1289305768,
"prev_timestamps": [
1289719410,
1289720747,
1289720862,
1289721420,
1289721693,
1289721830,
1289721987,
1289722615,
1289723015,
1289723356,
1289723346
]
},
"blocks": [
{
"header": {
"version": 1,
"time": 1289723848,
"bits": 453931606,
"nonce": 4000543654
},
"data": {
"variant_id": 1,
"transactions": [
{
"version": 1,
"is_segwit": false,
"inputs": [
{
"script": "0x0456720e1b00",
"sequence": 4294967295,
"previous_output": {
"txid": "0000000000000000000000000000000000000000000000000000000000000000",
"vout": 4294967295,
"data": {
"value": 0,
"pk_script": "0x",
"cached": false
},
"block_height": 0,
"median_time_past": 0,
"is_coinbase": false
},
"witness": [
"0x0000000000000000000000000000000000000000000000000000000000000000"
]
}
],
"outputs": [
{
"value": 5000000000,
"pk_script": "0x4104124b212f5416598a92ccec88819105179dcb2550d571842601492718273fe0f2179a9695096bff94cd99dcccdea7cd9bd943bfca8fea649cac963411979a33e9ac",
"cached": false
}
],
"lock_time": 0
}
]
}
}
],
"expected": {
"block_height": 91722,
"total_work": "120769201144676368",
"best_block_hash": "00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e",
"current_target": "5942996718418989293499865695368015163438891473576991811912597504",
"epoch_start_time": 1289305768,
"prev_timestamps": [
1289720747,
1289720862,
1289721420,
1289721693,
1289721830,
1289721987,
1289722615,
1289723015,
1289723356,
1289723346,
1289723848
]
}
}
56 changes: 56 additions & 0 deletions packages/client/tests/data/light_91721.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"chain_state": {
"block_height": 91721,
"total_work": "120749717356492800",
"best_block_hash": "00000000000a30044feb1a9010445c5b6d4cdc3f32ca747cff2525c32976ba42",
"current_target": "5942996718418989293499865695368015163438891473576991811912597504",
"epoch_start_time": 1289305768,
"prev_timestamps": [
1289719410,
1289720747,
1289720862,
1289721420,
1289721693,
1289721830,
1289721987,
1289722615,
1289723015,
1289723356,
1289723346
]
},
"blocks": [
{
"header": {
"version": 1,
"time": 1289723848,
"bits": 453931606,
"nonce": 4000543654
},
"data": {
"variant_id": 0,
"merkle_root": "e3bf3d07d4b0375638d5f1db5255fe07ba2c4cb067cd81b84ee974b6585fb468"
}
}
],
"expected": {
"block_height": 91722,
"total_work": "120769201144676368",
"best_block_hash": "00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e",
"current_target": "5942996718418989293499865695368015163438891473576991811912597504",
"epoch_start_time": 1289305768,
"prev_timestamps": [
1289720747,
1289720862,
1289721420,
1289721693,
1289721830,
1289721987,
1289722615,
1289723015,
1289723356,
1289723346,
1289723848
]
}
}
5 changes: 3 additions & 2 deletions packages/consensus/src/types/chain_state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ pub impl BlockValidatorImpl of BlockValidator {
let block_height = self.block_height + 1;

let prev_block_time = *self.prev_timestamps[self.prev_timestamps.len() - 1];

let median_time_past = compute_median_time_past(self.prev_timestamps);
maciejka marked this conversation as resolved.
Show resolved Hide resolved
let prev_timestamps = next_prev_timestamps(self.prev_timestamps, block.header.time);
let median_time_past = compute_median_time_past(prev_timestamps);

validate_timestamp(median_time_past, block.header.time)?;

let txid_root = match block.data {
TransactionData::MerkleRoot(root) => root,
TransactionData::Transactions(txs) => {
let (total_fees, txid_root, wtxid_root) = compute_and_validate_tx_data(
m-kus marked this conversation as resolved.
Show resolved Hide resolved
txs, block_height, block.header.time, ref utxo_set
txs, block_height, median_time_past, ref utxo_set
)?;
validate_coinbase(txs[0], total_fees, block_height, wtxid_root)?;
if execute_script {
Expand Down
4 changes: 2 additions & 2 deletions packages/consensus/src/types/utxo_set.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ pub impl UtxoSetImpl of UtxoSetTrait {
let status = self.cache.get(hash);
if status == TX_OUTPUT_STATUS_NONE {
// Extra check that can be removed later.
assert(!*outpoint.data.cached, 'cached output was not cached');
assert!(!*outpoint.data.cached, "cached output was not cached");

self.cache.insert(hash, TX_OUTPUT_STATUS_SPENT);
self.leaves_to_delete.append(hash);
Result::Ok(())
} else if status == TX_OUTPUT_STATUS_UNSPENT {
// Extra check that can be removed later.
assert(*outpoint.data.cached, 'non-cached output was cached');
assert!(*outpoint.data.cached, "non-cached output was cached");

self.cache.insert(hash, TX_OUTPUT_STATUS_SPENT);
self.num_cached -= 1;
Expand Down
8 changes: 7 additions & 1 deletion packages/consensus/src/validation/timestamp.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ pub fn validate_timestamp(median_time_past: u32, block_time: u32) -> Result<(),
if block_time > median_time_past {
Result::Ok(())
} else {
Result::Err("Median time past is greater than or equal to block's timestamp")
Result::Err(
format!(
"Median time past: {} >= block's timestamp: {}.",
median_time_past,
block_time
)
)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/consensus/src/validation/transaction.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ mod tests {
}

#[test]
#[should_panic(expected: 'cached output was not cached')]
#[should_panic(expected: "cached output was not cached")]
fn test_missed_cached_utxo() {
let block_height = 150;

Expand Down Expand Up @@ -586,7 +586,7 @@ mod tests {
}

#[test]
#[should_panic(expected: 'non-cached output was cached')]
#[should_panic(expected: "non-cached output was cached")]
fn test_wrongly_cached_utxo() {
let block_height = 150;

Expand Down
10 changes: 5 additions & 5 deletions packages/consensus/src/validation/work.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -65,38 +65,38 @@ mod tests {
let expected_work = 0x0100010001;
let target: u256 = 0x00000000ffff0000000000000000000000000000000000000000000000000000;
let work = compute_work_from_target(target);
assert(expected_work == work, 'Failed to compute target');
assert!(expected_work == work, "Failed to compute target");
}

#[test]
fn test_compute_work_from_target2() {
let expected_work = 0x26d946e509ac00026d;
let target: u256 = 0x00000000000000000696f4000000000000000000000000000000000000000000;
let work = compute_work_from_target(target);
assert(expected_work == work, 'Failed to compute target');
assert!(expected_work == work, "Failed to compute target");
}

#[test]
fn test_compute_work_from_target3() {
let expected_work = 0xe10005c64415f04ef3e387b97db388404db9fdfaab2b1918f6783471d;
let target: u256 = 0x12345600;
let work = compute_work_from_target(target);
assert(expected_work == work, 'Failed to compute target');
assert!(expected_work == work, "Failed to compute target");
}

#[test]
fn test_compute_work_from_target4() {
let expected_work = 0x1c040c95a099201bcaf85db4e7f2e21e18707c8d55a887643b95afb2f;
let target: u256 = 0x92340000;
let work = compute_work_from_target(target);
assert(expected_work == work, 'Failed to compute target');
assert!(expected_work == work, "Failed to compute target");
}

#[test]
fn test_compute_work_from_target5() {
let expected_work = 0x21809b468faa88dbe34f;
let target: u256 = 0x00000000000000000007a4290000000000000000000000000000000000000000;
let work = compute_work_from_target(target);
assert(expected_work == work, 'Failed to compute target');
assert!(expected_work == work, "Failed to compute target");
}
}
Loading
Loading