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

Development #51

Merged
merged 4 commits into from
Nov 27, 2024
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
16 changes: 11 additions & 5 deletions app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,13 @@ impl App {
.unwrap()
.unwrap_or(chain_spec.bitcoin_start_height);

let og_threshold = ((3 * 2) + 2) / 3;
let threshold = ((chain_spec.federation_bitcoin_pubkeys.len() * 2) + 2) / 3; // 2rds majority, rounded up
let og_bitcoin_federation = Federation::new(
chain_spec.federation_bitcoin_pubkeys[0..3].to_vec(),
og_threshold,
self.bitcoin_network,
);
let bitcoin_federation = Federation::new(
chain_spec.federation_bitcoin_pubkeys.clone(),
threshold,
Expand Down Expand Up @@ -240,6 +246,7 @@ impl App {
self.bitcoin_rpc_user.expect("RPC user is configured"),
self.bitcoin_rpc_pass.expect("RPC password is configured"),
),
og_bitcoin_federation.taproot_address.clone(),
bitcoin_federation.taproot_address.clone(),
),
bitcoin_wallet,
Expand Down Expand Up @@ -272,11 +279,10 @@ impl App {
chain.clone().listen_for_peer_discovery().await;
chain.clone().listen_for_rpc_requests().await;

chain
.clone()
.monitor_bitcoin_blocks(bitcoin_start_height)
.await;

if chain_spec.is_validator {
chain.clone().monitor_bitcoin_blocks(bitcoin_start_height).await;
}

AuraSlotWorker::new(
Duration::from_millis(slot_duration),
authorities,
Expand Down
10 changes: 6 additions & 4 deletions app/src/aura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ impl Aura {
.then_some(())
.ok_or(AuraError::BadSignature)?;

if !block.is_signed_by(expected_authority_index) {
return Err(AuraError::InvalidAuthor);
}
// TODO: Replace with dynamic sourcing for authorities at a given timespan
// if !block.is_signed_by(expected_authority_index) {
// return Err(AuraError::InvalidAuthor);
// }

Ok(())
}
Expand All @@ -114,7 +115,8 @@ impl Aura {

// + 2 makes this equal to `ceil((len*2) / 3.0)`
let required_signatures = if self.authorities.len() > 3 {
((self.authorities.len() * 2) + 2) / 3
// ((self.authorities.len() * 2) + 2) / 3
1
} else {
1
};
Expand Down
15 changes: 10 additions & 5 deletions app/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ impl NetworkBackend {
info!("Responding to rpc...");
self.swarm.behaviour_mut().eth2_rpc.send_response(peer_id, (connection_id, substream_id), payload);
}
Some(_) => {
debug!("Unhandled message");
}
None => {
// channel shut down, nothing to do
}
Expand All @@ -293,7 +296,7 @@ impl NetworkBackend {
message_id: id,
message,
})) => {
tracing::debug!(
debug!(
"Got message: '{}' with id: {id} from peer: {peer_id}",
String::from_utf8_lossy(&message.data),
);
Expand Down Expand Up @@ -345,10 +348,12 @@ impl NetworkBackend {
Ok(RPCReceived::EndOfStream(request_id, _)) => {
rpc_response_channels.remove(request_id);
}
Err(HandlerErr::Inbound { id: _, proto: _, error: _ }) => {
Err(HandlerErr::Inbound { id: err_stream_id, proto: _, error: stream_error }) => {
// not sure what to do with this, ignore for now
warn!("Inbound error: {:?}", stream_error);
}
Err(HandlerErr::Outbound { id: _, proto: _, error: _ }) => {
Err(HandlerErr::Outbound { id: stream_id, proto: _, error: stream_err }) => {
warn!("Outbound error: {:?}", stream_err);
}
}

Expand Down Expand Up @@ -450,8 +455,8 @@ fn create_swarm() -> Result<Swarm<MyBehaviour>, Error> {

let network_params = NetworkParams {
max_chunk_size: 1024 * 1024_usize,
ttfb_timeout: Duration::from_secs(15),
resp_timeout: Duration::from_secs(15),
ttfb_timeout: Duration::from_secs(180),
resp_timeout: Duration::from_secs(180),
};

let drain = slog::Discard;
Expand Down
1 change: 1 addition & 0 deletions app/src/network/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ impl<Id: ReqId, TSpec: EthSpec> RPC<Id, TSpec> {
}
};

tracing::debug!("Pushing RPC request to swarm request_id: {:?}, request_id: {:?}", request_id, peer_id);
self.events.push(event);
}

Expand Down
21 changes: 16 additions & 5 deletions crates/federation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ pub struct PegInInfo {
}

pub struct Bridge {
og_pegin_address: BitcoinAddress,
pegin_address: BitcoinAddress,
bitcoin_core: BitcoinCore,
}

impl Bridge {
const BRIDGE_CONTRACT_ADDRESS: &'static str = "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB";

pub fn new(bitcoin_core: BitcoinCore, pegin_address: BitcoinAddress) -> Self {
pub fn new(bitcoin_core: BitcoinCore, og_pegin_address: BitcoinAddress, pegin_address: BitcoinAddress) -> Self {
Self {
og_pegin_address,
pegin_address,
bitcoin_core,
}
Expand Down Expand Up @@ -135,8 +137,16 @@ impl Bridge {
.rpc
.get_raw_transaction(txid, Some(block_hash))?;

self.pegin_info(&tx, *block_hash, block_info.height as u32)
.ok_or(Error::NotAPegin)
let pegin_info = self.pegin_info(&tx, *block_hash, block_info.height as u32);

match pegin_info {
None => {
Err(Error::NotAPegin)
}
Some(info) => {
Ok(info)
}
}
}

pub fn fetch_transaction(&self, txid: &Txid, block_hash: &BlockHash) -> Option<Transaction> {
Expand Down Expand Up @@ -199,8 +209,9 @@ impl Bridge {
.output
.iter()
.find(|output| {
self.pegin_address
.matches_script_pubkey(&output.script_pubkey)
self.og_pegin_address
.matches_script_pubkey(&output.script_pubkey) || self.pegin_address
.matches_script_pubkey(&output.script_pubkey)
})
.map(|x| x.value)?;

Expand Down
2 changes: 1 addition & 1 deletion etc/config/chain.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
"powTargetTimespan": 12000,
"powTargetSpacing": 1000
},
"isValidator": true
"isValidator": false
}
1 change: 1 addition & 0 deletions scripts/start_geth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ echo "${NUM}"
#
# Initialize logs directory
mkdir -p "${BASE_DIR}/etc/data/logs"
touch "$(get_log_path $NUM)"

# Start the Geth node(s)
start_geth $NUM
Expand Down
11 changes: 8 additions & 3 deletions scripts/start_testnet_alys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ BASE_DIR=$(realpath "$SCRIPT_DIR/../")
BTC_RPC_USER=${BTC_RPC_USER:-"rpcuser"}
BTC_RPC_PASSWORD=${BTC_RPC_PASSWORD:-"rpcpassword"}
BTC_RPC_URL=${BTC_RPC_URL:-"http://localhost:18332"}
# Set default number of nodes if not already set
NUM=${NUM:-0}

echo "${NUM}"

# Initialize logs directory
# Initialize directories & log path
mkdir -p "${BASE_DIR}/etc/data/logs"
mkdir -p "$(get_data_path $NUM)"
touch "$(get_log_path $NUM)"

# Start the Geth node(s)
start_testnet_full_node
start_testnet_full_node $NUM

# Tail the log file to keep the shell open and display logs
tail -f "${PWD}/etc/data/logs/alys_0.txt"
tail -f "$(get_log_path $NUM)"
1 change: 1 addition & 0 deletions scripts/start_testnet_geth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ NUM=${NUM:-0}

# Initialize logs directory
mkdir -p "${BASE_DIR}/etc/data/logs"
touch "$(get_log_path $NUM)"

# Start the Geth node(s)
start_testnet_geth $NUM
Expand Down
15 changes: 14 additions & 1 deletion scripts/utils/chain.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function get_log_path() {
local node_NUM=$1
echo "${BASE_DIR}/etc/data/logs/consensus_${node_NUM}.txt"
}

function get_data_path() {
local node_NUM=$1
echo "${BASE_DIR}/etc/data/consensus/node_${node_NUM}"
}

function stop_all_chains() {
for pid in ${CHAIN_PIDS[*]}; do
echo "Killing chain $pid"
Expand Down Expand Up @@ -69,7 +79,10 @@ function start_full_node_from_genesis() {
}

function start_testnet_full_node() {
cargo run --bin app -- --chain "${PWD}/etc/config/chain.json" --geth-url http://localhost:8551/ --db-path "${PWD}/etc/data/consensus/node_0/chain_db" --rpc-port 3000 --wallet-path "${PWD}/etc/data/consensus/node_0" --bitcoin-rpc-url $BTC_RPC_URL --bitcoin-rpc-user $BTC_RPC_USER --bitcoin-rpc-pass $BTC_RPC_PASSWORD --bitcoin-network testnet --p2p-port 55444 --remote-bootnode /ip4/54.224.209.248/tcp/55444/ip4/107.22.120.71/tcp/55444/ip4/54.161.100.208/tcp/55444 > "${PWD}/etc/data/logs/alys_0.txt" 2>&1 &
local NUM=$1
local LOG_FILE=$(get_log_path $NUM)

cargo run --bin app -- --chain "${PWD}/etc/config/chain.json" --geth-url http://localhost:8551/ --db-path "$(get_data_path $NUM)/chain_db" --rpc-port 3000 --wallet-path "$(get_data_path $NUM)" --bitcoin-rpc-url $BTC_RPC_URL --bitcoin-rpc-user $BTC_RPC_USER --bitcoin-rpc-pass $BTC_RPC_PASSWORD --bitcoin-network testnet --p2p-port 55444 --remote-bootnode /ip4/54.161.100.208/tcp/55444 > "$LOG_FILE" 2>&1 &
CHAIN_PIDS[$NUM]=$!
}

Expand Down
33 changes: 23 additions & 10 deletions scripts/utils/geth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ function start_geth() {


# Define the file path
FILE_PATH="${BASE_DIR}/etc/data/execution/node_${NUM}/bootnode.key"
BOOTNODE_FILE_PATH="${BASE_DIR}/etc/data/execution/node_${NUM}/bootnode.key"
NODEKEY_FILE_PATH="${BASE_DIR}/etc/data/execution/node_${NUM}/geth/nodekey"

# Check if the file exists
if [ -f "$FILE_PATH" ]; then
if [ -f "$BOOTNODE_FILE_PATH" ]; then
# File exists, include the argument
ARGUMENT="--nodekey \"${BASE_DIR}/etc/data/execution/node_${NUM}/bootnode.key\""
ARGUMENT="--nodekey $BOOTNODE_FILE_PATH"
elif [ -f "$NODEKEY_FILE_PATH" ]; then
ARGUMENT="--nodekey $NODEKEY_FILE_PATH"
else
# File does not exist, do not include the argument
ARGUMENT=""
Expand Down Expand Up @@ -83,9 +86,7 @@ function start_testnet_geth() {
local LOG_FILE=$(get_log_path $NUM)


mkdir -p "${BASE_DIR}/etc/data/execution/node_${NUM}" "${BASE_DIR}/etc/data/logs"
touch "$LOG_FILE"

mkdir -p "${BASE_DIR}/etc/data/execution/node_${NUM}"

# Port calculations
local AUTHRPC_PORT=$((8551 + $NUM * 10))
Expand All @@ -96,7 +97,19 @@ function start_testnet_geth() {
# Initialize and start Geth
geth init --state.scheme "hash" --datadir "${BASE_DIR}/etc/data/execution/node_${NUM}" "${BASE_DIR}/etc/config/genesis.json" > "$LOG_FILE" 2>&1

bootnode -genkey "${BASE_DIR}/etc/data/execution/node_${NUM}/bootnode.key"
BOOTNODE_FILE_PATH="${BASE_DIR}/etc/data/execution/node_${NUM}/bootnode.key"
NODEKEY_FILE_PATH="${BASE_DIR}/etc/data/execution/node_${NUM}/geth/nodekey"

# Check if the file exists
if [ -f "$BOOTNODE_FILE_PATH" ]; then
# File exists, include the argument
ARGUMENT="--nodekey $BOOTNODE_FILE_PATH"
elif [ -f "$NODEKEY_FILE_PATH" ]; then
ARGUMENT="--nodekey $NODEKEY_FILE_PATH"
else
bootnode -genkey "$BOOTNODE_FILE_PATH"
ARGUMENT="--nodekey $BOOTNODE_FILE_PATH"
fi

geth --datadir "${BASE_DIR}/etc/data/execution/node_${NUM}" \
--state.scheme "hash" \
Expand All @@ -116,7 +129,7 @@ function start_testnet_geth() {
--ws.addr "0.0.0.0" \
--ws.port ${WS_PORT} \
--ws.origins "*" \
--verbosity 5 \
--verbosity 4 \
--log.file $LOG_FILE \
--gpo.ignoreprice 1 \
--metrics \
Expand All @@ -126,8 +139,8 @@ function start_testnet_geth() {
--port ${PORT} \
--gcmode "archive" \
--maxpeers 20 \
--nodekey "${BASE_DIR}/etc/data/execution/node_${NUM}/bootnode.key" \
--bootnodes "enode://6f8c2bfe5b83e79d0dfcf2a619af0a05ca178c5c22c30654db80e8e975133797cf704f0707f6b739731c89cf147fd6835500e632484064b048fdad141ccf542c@54.161.100.208:30303,enode://6fa3a059cde5853f5702fcba00d7d682dfd8af4140fc088fe19ced7aaf245c238377bfa2c3fbb058593c412cfd20b26192b86ba4266770beff79d9fb8a18bc07@107.22.120.71:30303" &
--bootnodes "enode://6f8c2bfe5b83e79d0dfcf2a619af0a05ca178c5c22c30654db80e8e975133797cf704f0707f6b739731c89cf147fd6835500e632484064b048fdad141ccf542c@54.161.100.208:30303" \
$ARGUMENT &
GETH_PIDS[$NUM]=$!
}

Expand Down
Loading