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

Check for Blocks before Contract Start and Adding Format Script #108

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"docker:bash": "docker compose exec agd bash",
"docker:make": "docker compose exec agd make -C /workspace/contract",
"make:help": "make list",
"start": "yarn docker:make clean start-contract",
"start": "./scripts/wait-for-chain.sh && yarn docker:make clean start-contract",
"build": "agoric run scripts/build-contract-deployer.js",
"test": "ava --verbose",
"lint": "tsc && eslint '**/*.js'",
Expand Down
33 changes: 33 additions & 0 deletions contract/scripts/wait-for-chain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Function to check if we see a pattern of block commits
check_block_pattern() {
local count=0
local required_patterns=3 # Number of block patterns we want to see

while IFS= read -r line; do
echo -n "." # Show progress

if [[ $line =~ "block-manager: block "[0-9]+" commit" ]]; then
((count++))
if [ $count -ge $required_patterns ]; then
echo
echo "$line"
amessbee marked this conversation as resolved.
Show resolved Hide resolved
return 0 # Success
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps show the whole line at this point; i.e. give evidence in the form of a timestamp and block number that things are running.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so rather than 150 lines of agd output in the ci log we would see...

Run yarn start:contract
Waiting for blockchain to start........(~150 dots)...
agd-1  | 2025-01-08T08:20:28.543Z block-manager: block 1227 commit
Blockchain is running and producing blocks...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

fi
fi
done

return 1 # Pattern not found
}

echo "Waiting for blockchain to start..."
yarn docker:logs | check_block_pattern

if [ $? -eq 0 ]; then
echo "Blockchain is running and producing blocks..."
exit 0
else
echo "Failed to detect blockchain activity\n Run yarn start:docker to start the blockchain first!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops... I should have checked this part; it doesn't seem to work for me. If I do yarn start:contract before yarn start:docker, I get:

$ yarn start:contract
Waiting for blockchain to start...
............
agd-1  | 2024-12-13T14:50:03.351Z block-manager: block 44932 commit
Blockchain is running and producing blocks...
service "agd" is not running

maybe that won't affect 1st time users
perhaps it's because I have stuff in my docker logs from an earlier run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work fine for me:

Waiting for blockchain to start...
Failed to detect blockchain activity\n Run yarn start:docker to start the blockchain first!

Although newline character is not treated as such due to missing -e I suppose. If I am going create a PR just for -e, I am going treat myself with red color added to the above line too.

exit 1
fi
Loading