Skip to content

Commit

Permalink
hotfix 🚑: Temporary fix for #47
Browse files Browse the repository at this point in the history
ISSUE: #47
  • Loading branch information
emailnjv committed Nov 27, 2024
1 parent b85001a commit a65486e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
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
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

0 comments on commit a65486e

Please sign in to comment.