From dca74b99d515f13ae8b0be7e2940f5f11acf0a91 Mon Sep 17 00:00:00 2001 From: Liam Monninger Date: Fri, 10 Nov 2023 16:32:35 -0800 Subject: [PATCH] chore: merge. --- m1/scripts/anr.sh | 22 ++++++++++++++++++++++ m1/scripts/avalanche-setup.sh | 25 +++++++++++++++++++++++++ m1/scripts/start-subnet.sh | 17 +++++++++++++++++ m1/subnet/.gitignore | 1 + m1/subnet/Cargo.toml | 20 +++++++++++--------- m1/subnet/src/vm/mod.rs | 24 +++++++++++++++++++++++- 6 files changed, 99 insertions(+), 10 deletions(-) create mode 100755 m1/scripts/anr.sh create mode 100755 m1/scripts/avalanche-setup.sh create mode 100755 m1/scripts/start-subnet.sh create mode 100644 m1/subnet/.gitignore diff --git a/m1/scripts/anr.sh b/m1/scripts/anr.sh new file mode 100755 index 00000000..e3482af1 --- /dev/null +++ b/m1/scripts/anr.sh @@ -0,0 +1,22 @@ +#!/bin/bash -e +mkdir -p ./plugins + +# We will inherit the avalanchego binary from the environment. +# But, we will set the plugin path to the plugin dir in this directory. +export AVALANCHEGO_EXEC_PATH=$(which avalanchego) +export AVALANCHEGO_PLUGIN_PATH=$(pwd)/plugins + +# Build the subnet +cargo build -p subnet + +# export SUBNET_ID=$(subnet-cli create VMID ./target/debug/subnet) +export SUBNET_ID=srEXiWaHZNDcVtfHLb38cFiwKVLJ8xnhDF5qpWbYdowxEiyid + +echo $SUBNET_ID +# Copy the subnet binary to the plugin dir +# cp ./target/debug/subnet ${AVALANCHEGO_PLUGIN_PATH}/${SUBNET_ID} +# cp ./target/debug/subnet ${AVALANCHEGO_PLUGIN_PATH}/subnet + +# Start the avalanche-network-runner +avalanche-network-runner server + diff --git a/m1/scripts/avalanche-setup.sh b/m1/scripts/avalanche-setup.sh new file mode 100755 index 00000000..1c0cc2ad --- /dev/null +++ b/m1/scripts/avalanche-setup.sh @@ -0,0 +1,25 @@ +#!/bin/bash -e + +# Install subnet-cli +VERSION=0.0.4 # Populate latest here + +GOARCH=$(go env GOARCH) +GOOS=$(go env GOOS) +DOWNLOAD_PATH=/tmp/subnet-cli.tar.gz +DOWNLOAD_URL=https://github.com/ava-labs/subnet-cli/releases/download/v${VERSION}/subnet-cli_${VERSION}_linux_${GOARCH}.tar.gz +if [[ ${GOOS} == "darwin" ]]; then + DOWNLOAD_URL=https://github.com/ava-labs/subnet-cli/releases/download/v${VERSION}/subnet-cli_${VERSION}_darwin_${GOARCH}.tar.gz +fi + +rm -f ${DOWNLOAD_PATH} +rm -f /tmp/subnet-cli + +echo "downloading subnet-cli ${VERSION} at ${DOWNLOAD_URL}" +curl -L ${DOWNLOAD_URL} -o ${DOWNLOAD_PATH} + +echo "extracting downloaded subnet-cli" +tar xzvf ${DOWNLOAD_PATH} -C /tmp + +/tmp/subnet-cli -h + +cp /tmp/subnet-cli $HOME/bin/subnet-cli \ No newline at end of file diff --git a/m1/scripts/start-subnet.sh b/m1/scripts/start-subnet.sh new file mode 100755 index 00000000..9b0c4b91 --- /dev/null +++ b/m1/scripts/start-subnet.sh @@ -0,0 +1,17 @@ +#!/bin/bash -e +export AVALANCHEGO_EXEC_PATH=$(which avalanchego) +export AVALANCHEGO_PLUGIN_PATH=$(pwd)/plugins + +echo hello > /tmp/subnet.genesis.json + +avalanche-network-runner control start \ +--log-level debug \ +--endpoint="0.0.0.0:8080" \ +--avalanchego-path="${AVALANCHEGO_EXEC_PATH}" +# --blockchain-specs '[{"vm_name":"subnet","genesis":"/tmp/subnet.genesis.json","blockchain_alias":"movement"}]' \ + +# avalanche-network-runner control create-blockchains '[{"vm_name":"movement", "subnet_id": "srEXiWaHZNDcVtfHLb38cFiwKVLJ8xnhDF5qpWbYdowxEiyid"}]' \ +# --log-level debug \ +# --endpoint="0.0.0.0:8080" + +curl -X POST -k http://localhost:8081/v1/control/status \ No newline at end of file diff --git a/m1/subnet/.gitignore b/m1/subnet/.gitignore new file mode 100644 index 00000000..f4f388c8 --- /dev/null +++ b/m1/subnet/.gitignore @@ -0,0 +1 @@ +plugins \ No newline at end of file diff --git a/m1/subnet/Cargo.toml b/m1/subnet/Cargo.toml index c70a118c..112355a0 100644 --- a/m1/subnet/Cargo.toml +++ b/m1/subnet/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -avalanche-types = { version = "0.0.398", features = ["subnet", "codec_base64"] } +avalanche-types = { version = "0.1.3", features = ["subnet", "codec_base64"] } tokio = { version = "1.25.0", features = ["fs", "rt-multi-thread"] } tonic = { version = "0.8.3", features = ["gzip"] } serde = { version = "1.0.152", features = ["derive"] } @@ -17,22 +17,22 @@ dirs = "5.0.1" hex = "0.4.3" bytes = "1.4.0" env_logger = "0.10.0" -base64 = { version = "0.21.0" } +# base64 = { version = "0.21.0" } chrono = "0.4.23" derivative = "2.2.0" jsonrpc-core = "18.0.0" jsonrpc-core-client = { version = "18.0.0" } jsonrpc-derive = "18.0.0" -anyhow = { workspace = true } +# anyhow = { workspace = true } aptos-config = { workspace = true } -aptos-consensus-types = { workspace = true } +# aptos-consensus-types = { workspace = true } aptos-mempool = { workspace = true } -aptos-runtimes = { workspace = true } +# aptos-runtimes = { workspace = true } aptos-crypto = { workspace = true } aptos-db = { workspace = true, features = ["fuzzing"] } aptos-executor = { workspace = true } -aptos-logger = { workspace = true } +# aptos-logger = { workspace = true } aptos-api-types = { workspace = true } aptos-api = { workspace = true } aptos-executor-types = { workspace = true } @@ -40,10 +40,12 @@ aptos-genesis = { workspace = true } aptos-sdk = { workspace = true } aptos-state-view = { workspace = true } aptos-storage-interface = { workspace = true } -aptos-temppath = { workspace = true } +# aptos-temppath = { workspace = true } aptos-types = { workspace = true } aptos-vm = { workspace = true } futures = { workspace = true } aptos-vm-genesis = { workspace = true } -rand = { workspace = true } -bcs = { workspace = true } \ No newline at end of file +# rand = { workspace = true } +bcs = { workspace = true } +aptos-node = { workspace = true, features = ["indexer"] } +aptos-indexer-grpc-fullnode = { workspace = true } diff --git a/m1/subnet/src/vm/mod.rs b/m1/subnet/src/vm/mod.rs index bbdefb38..8123205a 100644 --- a/m1/subnet/src/vm/mod.rs +++ b/m1/subnet/src/vm/mod.rs @@ -55,6 +55,8 @@ use aptos_types::transaction::Transaction::UserTransaction; use aptos_types::validator_signer::ValidatorSigner; use aptos_vm::AptosVM; use aptos_vm_genesis::{GENESIS_KEYPAIR, test_genesis_change_set_and_validators}; +use aptos_node::indexer::bootstrap_indexer; +use aptos_indexer_grpc_fullnode::runtime::bootstrap as bootstrap_indexer_grpc; use crate::{block::Block, state}; use crate::api::chain_handlers::{AccountStateArgs, BlockArgs, ChainHandler, ChainService, GetTransactionByVersionArgs, PageArgs, RpcEventHandleReq, RpcEventNumReq, RpcReq, RpcRes, RpcTableReq}; @@ -1338,7 +1340,7 @@ impl Vm { // set up the mempool let (mempool_client_sender, mut mempool_client_receiver) = futures_mpsc::channel::(10); - let sender = MempoolClientSender::from(mempool_client_sender); + let sender = MempoolClientSender::from(mempool_client_sender.clone()); let node_config = NodeConfig::default(); let context = Context::new(ChainId::test(), db.1.reader.clone(), @@ -1368,6 +1370,12 @@ impl Vm { } }); + // start the indexer service + tokio::task::spawn(async move { + bootstrap_indexer_grpc(&node_config, ChainId::test(), db.1.reader.clone(), mempool_client_sender.clone()).unwrap(); + bootstrap_indexer(&node_config, ChainId::test(), db.1.reader.clone(), MempoolClientSender::from(mempool_client_sender.clone())).unwrap(); + }); + } } @@ -1476,6 +1484,20 @@ impl ChainVm for Vm async fn last_accepted(&self) -> io::Result { self.last_accepted().await } + + async fn verify_height_index(&self) -> io::Result<()> { + Ok(()) + } + + // Returns an error as a no-op for now. + async fn get_block_id_at_height(&self, _height: u64) -> io::Result { + Err(Error::new(ErrorKind::NotFound, "block id not found")) + } + + async fn state_sync_enabled(&self) -> io::Result { + Ok(false) + } + } #[tonic::async_trait]