Skip to content

Commit

Permalink
fix: Add p2p node to example scripts (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidan46 authored Jan 15, 2025
1 parent 8c84b15 commit 731e867
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
17 changes: 15 additions & 2 deletions examples/rpc_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 &

Expand All @@ -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")"
Expand Down
15 changes: 13 additions & 2 deletions examples/start_sp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand All @@ -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
Expand All @@ -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" \
Expand Down
3 changes: 2 additions & 1 deletion storage-provider/server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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<PeerId>,
}
3 changes: 2 additions & 1 deletion storage-provider/server/src/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 731e867

Please sign in to comment.