From 731e867e9b0ba4af733d7086e6902dbff5d899ad Mon Sep 17 00:00:00 2001 From: aidan46 <47111423+aidan46@users.noreply.github.com> Date: Wed, 15 Jan 2025 09:19:49 +0100 Subject: [PATCH] fix: Add p2p node to example scripts (#673) --- examples/rpc_publish.sh | 17 +++++++++++++++-- examples/start_sp.sh | 15 +++++++++++++-- storage-provider/server/src/config.rs | 3 ++- storage-provider/server/src/p2p.rs | 3 ++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/examples/rpc_publish.sh b/examples/rpc_publish.sh index d22693e42..5e2437445 100755 --- a/examples/rpc_publish.sh +++ b/examples/rpc_publish.sh @@ -22,11 +22,24 @@ PROVIDER="//Charlie" INPUT_FILE="$1" INPUT_FILE_NAME="$(basename "$INPUT_FILE")" INPUT_TMP_FILE="/tmp/$INPUT_FILE_NAME.car" +P2P_PUBLIC_KEY="/tmp/public.pem" +P2P_PRIVATE_KEY="/tmp/private.pem" +P2P_ADDRESS="/ip4/127.0.0.1/tcp/62649" +# Generate ED25519 private key +openssl genpkey -algorithm ED25519 -out "$P2P_PRIVATE_KEY" -outpubkey "$P2P_PUBLIC_KEY" target/release/mater-cli convert -q --overwrite "$INPUT_FILE" "$INPUT_TMP_FILE" && INPUT_COMMP="$(target/release/polka-storage-provider-client proofs commp "$INPUT_TMP_FILE")" PIECE_CID="$(echo "$INPUT_COMMP" | jq -r ".cid")" PIECE_SIZE="$(echo "$INPUT_COMMP" | jq ".size")" +PEER_ID="$(target/release/polka-storage-provider-client generate-peer-id --pubkey "$P2P_PUBLIC_KEY")" +CONFIG="/tmp/bootstrap.toml" +echo "seal_proof = '2KiB' +post_proof = '2KiB' +porep_parameters = '2KiB.porep.params' +post_parameters = '2KiB.post.params' +rendezvous_point_address = '$P2P_ADDRESS' +p2p_key = '@$P2P_PRIVATE_KEY'" > "$CONFIG" # Setup balances @@ -39,7 +52,7 @@ wait # It's a test setup based on the local verifying keys, everyone can run those extrinsics currently. # Each of the keys is different, because the processes are running in parallel. # If they were running in parallel on the same account, they'd conflict with each other on the transaction nonce. -target/release/storagext-cli --sr25519-key "//Charlie" storage-provider register "peer_id" & +target/release/storagext-cli --sr25519-key "//Charlie" storage-provider register "$PEER_ID" & target/release/storagext-cli --sr25519-key "//Alice" proofs set-porep-verifying-key @2KiB.porep.vk.scale & target/release/storagext-cli --sr25519-key "//Bob" proofs set-post-verifying-key @2KiB.post.vk.scale & @@ -64,7 +77,7 @@ DEAL_JSON=$( ) SIGNED_DEAL_JSON="$(RUST_LOG=error target/release/polka-storage-provider-client sign-deal --sr25519-key "$CLIENT" "$DEAL_JSON")" -(RUST_LOG=debug target/release/polka-storage-provider-server --sr25519-key "$PROVIDER" --seal-proof "2KiB" --post-proof "2KiB" --porep-parameters 2KiB.porep.params --post-parameters 2KiB.post.params) & +(RUST_LOG=debug target/release/polka-storage-provider-server --sr25519-key "$PROVIDER" --config "$CONFIG") & sleep 5 # gives time for the server to start DEAL_CID="$(RUST_LOG=error target/release/polka-storage-provider-client propose-deal "$DEAL_JSON")" diff --git a/examples/start_sp.sh b/examples/start_sp.sh index 47f48f416..4d10421e3 100755 --- a/examples/start_sp.sh +++ b/examples/start_sp.sh @@ -8,6 +8,15 @@ export DISABLE_XT_WAIT_WARNING=1 CLIENT="//Alice" PROVIDER="//Charlie" +P2P_PUBLIC_KEY="/tmp/public.pem" +P2P_PRIVATE_KEY="/tmp/private.pem" +P2P_ADDRESS="/ip4/127.0.0.1/tcp/62649" + +# Generate ED25519 private key +openssl genpkey -algorithm ED25519 -out "$P2P_PRIVATE_KEY" -outpubkey "$P2P_PUBLIC_KEY" + +# Generate Peer ID +PEER_ID="$(target/release/polka-storage-provider-client generate-peer-id --pubkey "$P2P_PUBLIC_KEY")" # Setup balances RUST_LOG=debug target/release/storagext-cli --sr25519-key "$CLIENT" market add-balance 250000000000 & @@ -19,7 +28,7 @@ wait # It's a test setup based on the local verifying keys, everyone can run those extrinsics currently. # Each of the keys is different, because the processes are running in parallel. # If they were running in parallel on the same account, they'd conflict with each other on the transaction nonce. -RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Charlie" storage-provider register "peer_id" & +RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Charlie" storage-provider register "$PEER_ID" & RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Alice" proofs set-porep-verifying-key @2KiB.porep.vk.scale & RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Bob" proofs set-post-verifying-key @2KiB.post.vk.scale & wait @@ -28,7 +37,9 @@ echo '{ "seal_proof": "2KiB", "post_proof": "2KiB", "porep_parameters": "2KiB.porep.params", - "post_parameters": "2KiB.post.params" + "post_parameters": "2KiB.post.params", + "p2p_key": "@/tmp/private.pem", + "rendezvous_point_address": "/ip4/127.0.0.1/tcp/62649" }' > /tmp/storage_provider.config.json RUST_LOG=debug target/release/polka-storage-provider-server \ --sr25519-key "$PROVIDER" \ diff --git a/storage-provider/server/src/config.rs b/storage-provider/server/src/config.rs index 1c0bf4414..2235cfb89 100644 --- a/storage-provider/server/src/config.rs +++ b/storage-provider/server/src/config.rs @@ -104,6 +104,7 @@ pub struct ConfigurationArgs { pub(crate) post_parameters: PathBuf, /// P2P Node type, can be either a bootstrap node or a registration node. + #[serde(default = "NodeType::default")] #[arg(long, default_value = "bootstrap")] pub(crate) node_type: NodeType, @@ -120,6 +121,6 @@ pub struct ConfigurationArgs { /// PeerID of the bootstrap node used by the registration node. /// Optional because it is not used by the bootstrap node. #[arg(long)] - #[serde(deserialize_with = "string_to_peer_id_option")] + #[serde(default, deserialize_with = "string_to_peer_id_option")] pub(crate) rendezvous_point: Option, } diff --git a/storage-provider/server/src/p2p.rs b/storage-provider/server/src/p2p.rs index 52e93a375..8821fec45 100644 --- a/storage-provider/server/src/p2p.rs +++ b/storage-provider/server/src/p2p.rs @@ -20,8 +20,9 @@ pub(crate) use register::RegisterConfig; const P2P_NAMESPACE: &str = "polka-storage"; -#[derive(Debug, Clone, Copy, ValueEnum, Deserialize)] +#[derive(Default, Debug, Clone, Copy, ValueEnum, Deserialize)] pub enum NodeType { + #[default] Bootstrap, Register, }