Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into breaking-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Feb 29, 2024
2 parents 410045c + f829633 commit d2f9c4f
Show file tree
Hide file tree
Showing 41 changed files with 1,520 additions and 624 deletions.
230 changes: 230 additions & 0 deletions .github/workflows/assertoor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
name: Assertoor Tests

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
get_tests:
name: "Run assertoor tests on reth pairs"
runs-on: ubuntu-latest
outputs:
test_result: ${{ steps.test_result.outputs.test_result }}
test_status: ${{ steps.test_result.outputs.test_status }}
failed_test_status: ${{ steps.test_result.outputs.failed_test_status }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Kurtosis
shell: bash
run: |
echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
sudo apt update
sudo apt install kurtosis-cli
kurtosis analytics disable
- name: Run Kurtosis
shell: bash
id: services
run: |
export github_sha=${{ github.sha }}
export github_repository=${{ github.repository }}
cat etc/assertoor/assertoor-template.yaml | envsubst > etc/assertoor/assertoor.yaml
kurtosis run github.com/kurtosis-tech/ethereum-package --enclave assertoor-${{ github.run_id }} --args-file etc/assertoor/assertoor.yaml
enclave_dump=$(kurtosis enclave inspect assertoor-${{ github.run_id }})
assertoor_url=$(echo "$enclave_dump" | grep assertoor | grep http | sed 's/.*\(http:\/\/[0-9.:]\+\).*/\1/')
echo "assertoor_url: ${assertoor_url}"
echo "assertoor_url=${assertoor_url}" >> $GITHUB_OUTPUT
- name: Await test completion
shell: bash
id: test_result
run: |
assertoor_url="${{ steps.services.outputs.assertoor_url }}"
YELLOW='\033[1;33m'
GRAY='\033[0;37m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
# print assertor logs
assertoor_container=$(docker container list | grep assertoor | sed 's/^\([^ ]\+\) .*$/\1/')
docker logs -f $assertoor_container &
# helper to fetch task status for specific test id
get_tasks_status() {
tasks=$(curl -s ${assertoor_url}/api/v1/test_run/$1 | jq -c ".data.tasks[] | {index, parent_index, name, title, status, result}")
declare -A task_graph_map
task_graph_map[0]=""
while read task; do
task_id=$(echo "$task" | jq -r ".index")
task_parent=$(echo "$task" | jq -r ".parent_index")
task_name=$(echo "$task" | jq -r ".name")
task_title=$(echo "$task" | jq -r ".title")
task_status=$(echo "$task" | jq -r ".status")
task_result=$(echo "$task" | jq -r ".result")
task_graph="${task_graph_map[$task_parent]}"
task_graph_map[$task_id]="$task_graph |"
if [ ! -z "$task_graph" ]; then
task_graph="${task_graph}- "
fi
if [ "$task_status" == "pending" ]; then
task_status="${GRAY}pending ${NC}"
elif [ "$task_status" == "running" ]; then
task_status="${YELLOW}running ${NC}"
elif [ "$task_status" == "complete" ]; then
task_status="${GREEN}complete${NC}"
fi
if [ "$task_result" == "none" ]; then
task_result="${GRAY}none ${NC}"
elif [ "$task_result" == "success" ]; then
task_result="${GREEN}success${NC}"
elif [ "$task_result" == "failure" ]; then
task_result="${RED}failure${NC}"
fi
echo -e " $(printf '%-4s' "$task_id")\t$task_status\t$task_result\t$(printf '%-50s' "$task_graph$task_name") \t$task_title"
done <<< $(echo "$tasks")
}
# poll & check test status
final_test_result=""
failed_test_id=""
while true
do
pending_tests=0
failed_tests=0
total_tests=0
running_test=""
status_lines=()
task_lines=""
status_lines+=("$(date +'%Y-%m-%d %H:%M:%S') Test Status:")
tests=$(curl -s ${assertoor_url}/api/v1/test_runs | jq -c ".data[] | {run_id, test_id, name, status}")
while read test; do
if [ -z "$test" ]; then
continue
fi
run_id=$(echo "$test" | jq -r ".run_id")
test_id=$(echo "$test" | jq -r ".test_id")
test_name=$(echo "$test" | jq -r ".name")
test_status=$(echo "$test" | jq -r ".status")
if [ "$test_status" == "pending" ]; then
pending_tests=$(expr $pending_tests + 1)
status_name="${GRAY}pending${NC}"
elif [ "$test_status" == "running" ]; then
pending_tests=$(expr $pending_tests + 1)
running_test="$run_id"
status_name="${YELLOW}running${NC}"
elif [ "$test_status" == "success" ]; then
status_name="${GREEN}success${NC}"
elif [ "$test_status" == "failure" ]; then
failed_tests=$(expr $failed_tests + 1)
failed_test_id="$run_id"
status_name="${RED}failure${NC}"
else
status_name="$test_status"
fi
status_lines+=(" $(printf '%-3s' "$test_id") $status_name \t$test_name")
total_tests=$(expr $total_tests + 1)
done <<< $(echo "$tests")
for status_line in "${status_lines[@]}"
do
echo -e "$status_line"
done
if ! [ -z "$running_test" ]; then
task_lines=$(get_tasks_status "$running_test")
echo "Active Test Task Status:"
echo "$task_lines"
fi
if [ $failed_tests -gt 0 ]; then
final_test_result="failure"
break
fi
if [ $total_tests -gt 0 ] && [ $pending_tests -le 0 ]; then
final_test_result="success"
break
fi
sleep 60
done
# save test results & status to github output
echo "test_result=$(echo "$final_test_result")" >> $GITHUB_OUTPUT
echo "test_status<<EOF" >> $GITHUB_OUTPUT
for status_line in "${status_lines[@]}"
do
echo -e "$status_line" >> $GITHUB_OUTPUT
done
echo "EOF" >> $GITHUB_OUTPUT
if ! [ -z "$failed_test_id" ]; then
echo "failed_test_status<<EOF" >> $GITHUB_OUTPUT
get_tasks_status "$failed_test_id" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "failed_test_status=" >> $GITHUB_OUTPUT
fi
- name: Generate dump and remove kurtosis enclave
shell: bash
run: |
mkdir -p ./temp/dump
cd ./temp/dump
cp ../../etc/assertoor/assertoor.yaml ./kurtosis-params.yaml
kurtosis enclave dump assertoor-${{ github.run_id }}
kurtosis enclave rm -f assertoor-${{ github.run_id }}
- name: Upload dump artifact
uses: actions/upload-artifact@v3
with:
name: "kurtosis-enclave-dump-${{ github.run_id }}"
path: ./temp/dump

- name: Return test result
shell: bash
run: |
test_result="${{ steps.test_result.outputs.test_result }}"
test_status=$(
cat <<"EOF"
${{ steps.test_result.outputs.test_status }}
EOF
)
failed_test_status=$(
cat <<"EOF"
${{ steps.test_result.outputs.failed_test_status }}
EOF
)
echo "Test Result: $test_result"
echo "$test_status"
if ! [ "$test_result" == "success" ]; then
echo ""
echo "Failed Test Task Status:"
echo "$failed_test_status"
echo ""
echo "See 'Await test completion' task for detailed logs about this failure!"
echo ""
exit 1 # fail action
fi
7 changes: 4 additions & 3 deletions bin/reth/src/commands/test_vectors/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ pub(crate) fn generate_vectors(mut tables: Vec<String>) -> Result<()> {
}

/// Generates test-vectors for normal tables. Keys are sorted and not repeated.
fn generate_table_vector<T: Table>(runner: &mut TestRunner, per_table: usize) -> Result<()>
fn generate_table_vector<T>(runner: &mut TestRunner, per_table: usize) -> Result<()>
where
T::Key: Arbitrary + serde::Serialize + Ord + std::hash::Hash,
T::Value: Arbitrary + serde::Serialize,
T: Table,
{
let mut rows = vec![];
let mut seen_keys = HashSet::new();
Expand Down Expand Up @@ -109,9 +110,9 @@ where

/// Generates test-vectors for DUPSORT tables. Each key has multiple (subkey, value). Keys and
/// subkeys are sorted.
fn generate_dupsort_vector<T: Table>(runner: &mut TestRunner, per_table: usize) -> Result<()>
fn generate_dupsort_vector<T>(runner: &mut TestRunner, per_table: usize) -> Result<()>
where
T: DupSort,
T: Table + DupSort,
T::Key: Arbitrary + serde::Serialize + Ord + std::hash::Hash,
T::Value: Arbitrary + serde::Serialize + Ord,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/block_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mod tests {

/// Assert that the block was removed from all buffer collections.
fn assert_block_removal(buffer: &BlockBuffer, block: &SealedBlockWithSenders) {
assert!(buffer.blocks.get(&block.hash()).is_none());
assert!(!buffer.blocks.contains_key(&block.hash()));
assert!(buffer
.parent_to_child
.get(&block.parent_hash)
Expand Down
58 changes: 13 additions & 45 deletions crates/consensus/auto-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,13 @@ impl StorageInner {

/// Fills in the post-execution header fields based on the given BundleState and gas used.
/// In doing this, the state root is calculated and the final header is returned.
///
/// This is optimism-specific and contains the `ChainSpec` so the proper state root can be
/// calculated.
#[cfg(feature = "optimism")]
pub(crate) fn complete_header<S: StateProviderFactory>(
&self,
mut header: Header,
bundle_state: &BundleStateWithReceipts,
client: &S,
gas_used: u64,
chain_spec: &ChainSpec,
#[cfg(feature = "optimism")] chain_spec: &ChainSpec,
) -> Result<Header, BlockExecutionError> {
let receipts = bundle_state.receipts_by_block(header.number);
header.receipts_root = if receipts.is_empty() {
Expand All @@ -369,46 +365,18 @@ impl StorageInner {
.collect::<Vec<ReceiptWithBloom>>();
header.logs_bloom =
receipts_with_bloom.iter().fold(Bloom::ZERO, |bloom, r| bloom | r.bloom);
proofs::calculate_receipt_root_optimism(
&receipts_with_bloom,
chain_spec,
header.timestamp,
)
};

header.gas_used = gas_used;

// calculate the state root
let state_root = client
.latest()
.map_err(|_| BlockExecutionError::ProviderError)?
.state_root(bundle_state)
.unwrap();
header.state_root = state_root;
Ok(header)
}

/// Fills in the post-execution header fields based on the given BundleState and gas used.
/// In doing this, the state root is calculated and the final header is returned.
#[cfg(not(feature = "optimism"))]
pub(crate) fn complete_header<S: StateProviderFactory>(
&self,
mut header: Header,
bundle_state: &BundleStateWithReceipts,
client: &S,
gas_used: u64,
) -> Result<Header, BlockExecutionError> {
let receipts = bundle_state.receipts_by_block(header.number);
header.receipts_root = if receipts.is_empty() {
EMPTY_RECEIPTS
} else {
let receipts_with_bloom = receipts
.iter()
.map(|r| (*r).clone().expect("receipts have not been pruned").into())
.collect::<Vec<ReceiptWithBloom>>();
header.logs_bloom =
receipts_with_bloom.iter().fold(Bloom::ZERO, |bloom, r| bloom | r.bloom);
proofs::calculate_receipt_root(&receipts_with_bloom)
#[cfg(feature = "optimism")]
{
proofs::calculate_receipt_root_optimism(
&receipts_with_bloom,
chain_spec,
header.timestamp,
)
}
#[cfg(not(feature = "optimism"))]
{
proofs::calculate_receipt_root(&receipts_with_bloom)
}
};

header.gas_used = gas_used;
Expand Down
Loading

0 comments on commit d2f9c4f

Please sign in to comment.