Skip to content

Commit 3c74e42

Browse files
authored
Merge branch 'openmina:develop' into develop
2 parents 969fa3b + 93fba7b commit 3c74e42

File tree

44 files changed

+964
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+964
-529
lines changed

cli/src/commands/node/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,12 @@ impl Node {
226226

227227
if let Some(producer_key_path) = self.producer_key {
228228
let password = &self.producer_key_password;
229-
node::core::info!(node::core::log::system_time(); summary = "loading provers index");
230-
let provers = BlockProver::make(Some(block_verifier_index), Some(work_verifier_index));
231-
node::core::info!(node::core::log::system_time(); summary = "loaded provers index");
232-
node_builder.block_producer_from_file(provers, producer_key_path, password)?;
229+
openmina_core::thread::spawn(|| {
230+
node::core::info!(node::core::log::system_time(); summary = "loading provers index");
231+
BlockProver::make(Some(block_verifier_index), Some(work_verifier_index));
232+
node::core::info!(node::core::log::system_time(); summary = "loaded provers index");
233+
});
234+
node_builder.block_producer_from_file(producer_key_path, password, None)?;
233235

234236
if let Some(pub_key) = self.coinbase_receiver {
235237
node_builder

core/src/consensus.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use time::{macros::format_description, OffsetDateTime};
77

88
use crate::constants::constraint_constants;
99
pub use crate::constants::{
10-
checkpoint_window_size_in_slots, grace_period_end, slots_per_window, CHECKPOINTS_PER_YEAR,
10+
checkpoint_window_size_in_slots, slots_per_window, CHECKPOINTS_PER_YEAR,
1111
};
1212

1313
// TODO get constants from elsewhere
@@ -39,21 +39,21 @@ pub fn is_short_range_fork(a: &MinaConsensusState, b: &MinaConsensusState) -> bo
3939
if s1.epoch_count.as_u32() == s2.epoch_count.as_u32() + 1
4040
&& s2_epoch_slot >= slots_per_epoch * 2 / 3
4141
{
42-
crate::log::debug!(crate::log::system_time(); kind = "is_short_range_fork", msg = format!("s2 is 1 epoch behind and not in seed update range: {} vs {}", s1.staking_epoch_data.lock_checkpoint, s2.next_epoch_data.lock_checkpoint));
42+
crate::log::trace!(crate::log::system_time(); kind = "is_short_range_fork", msg = format!("s2 is 1 epoch behind and not in seed update range: {} vs {}", s1.staking_epoch_data.lock_checkpoint, s2.next_epoch_data.lock_checkpoint));
4343
// S1 is one epoch ahead of S2 and S2 is not in the seed update range
4444
s1.staking_epoch_data.lock_checkpoint == s2.next_epoch_data.lock_checkpoint
4545
} else {
46-
crate::log::debug!(crate::log::system_time(); kind = "is_short_range_fork", msg = format!("chains are from different epochs"));
46+
crate::log::trace!(crate::log::system_time(); kind = "is_short_range_fork", msg = format!("chains are from different epochs"));
4747
false
4848
}
4949
};
5050

51-
crate::log::debug!(crate::log::system_time(); kind = "is_short_range_fork", msg = format!("epoch count: {} vs {}", a.epoch_count.as_u32(), b.epoch_count.as_u32()));
51+
crate::log::trace!(crate::log::system_time(); kind = "is_short_range_fork", msg = format!("epoch count: {} vs {}", a.epoch_count.as_u32(), b.epoch_count.as_u32()));
5252
if a.epoch_count == b.epoch_count {
5353
let a_prev_lock_checkpoint = &a.staking_epoch_data.lock_checkpoint;
5454
let b_prev_lock_checkpoint = &b.staking_epoch_data.lock_checkpoint;
5555
// Simple case: blocks have same previous epoch, so compare previous epochs' lock_checkpoints
56-
crate::log::debug!(crate::log::system_time(); kind = "is_short_range_fork", msg = format!("checkpoints: {} vs {}", a_prev_lock_checkpoint, b_prev_lock_checkpoint));
56+
crate::log::trace!(crate::log::system_time(); kind = "is_short_range_fork", msg = format!("checkpoints: {} vs {}", a_prev_lock_checkpoint, b_prev_lock_checkpoint));
5757
a_prev_lock_checkpoint == b_prev_lock_checkpoint
5858
} else {
5959
// Check for previous epoch case using both orientations

core/src/constants.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,6 @@ pub fn checkpoint_window_size_in_slots() -> u32 {
107107
size_in_slots as u32
108108
}
109109

110-
pub fn grace_period_end(constants: &v2::MinaBaseProtocolConstantsCheckedValueStableV1) -> u32 {
111-
let slots = {
112-
const NUM_DAYS: u64 = 3;
113-
let n_days_ms = days_to_ms(NUM_DAYS);
114-
let n_days = n_days_ms / constraint_constants().block_window_duration_ms;
115-
(n_days as u32).min(constants.slots_per_epoch.as_u32())
116-
};
117-
match constraint_constants().fork.as_ref() {
118-
None => slots,
119-
Some(fork) => slots + fork.global_slot_since_genesis,
120-
}
121-
}
122-
123110
pub const DEFAULT_GENESIS_TIMESTAMP_MILLISECONDS: u64 = 1707157200000;
124111

125112
pub const PROTOCOL_TRANSACTION_VERSION: u8 = 3;

core/src/thread.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ mod main_thread {
7373
}));
7474
rx.await.ok()
7575
}
76+
77+
pub fn run_async_fn_in_main_thread_blocking<F, FU, T>(f: F) -> Option<T>
78+
where
79+
T: 'static + Send,
80+
FU: Future<Output = T>,
81+
F: 'static + Send + FnOnce() -> FU,
82+
{
83+
let sender = MAIN_THREAD_TASK_SENDER
84+
.get()
85+
.expect("main thread not initialized");
86+
let (tx, rx) = oneshot::channel();
87+
let _ = sender.send(Box::pin(async move {
88+
wasm_bindgen_futures::spawn_local(async move {
89+
let _ = tx.send(f().await);
90+
})
91+
}));
92+
rx.blocking_recv().ok()
93+
}
7694
}
7795
#[cfg(target_family = "wasm")]
7896
pub use main_thread::*;

docker-compose.block-producer.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ services:
22
openmina-node:
33
image: openmina/openmina:${OPENMINA_TAG:-latest}
44
entrypoint: >
5-
sh -c "openmina node --producer-key /root/.openmina/producer-key $${COINBASE_RECEIVER:+--coinbase-receiver $$COINBASE_RECEIVER} $${OPENMINA_LIBP2P_EXTERNAL_IP:+--libp2p-external-ip $$OPENMINA_LIBP2P_EXTERNAL_IP}"
5+
sh -c "openmina node --producer-key /root/.openmina/producer-key $${COINBASE_RECEIVER:+--coinbase-receiver $$COINBASE_RECEIVER} $${OPENMINA_LIBP2P_EXTERNAL_IP:+--libp2p-external-ip $$OPENMINA_LIBP2P_EXTERNAL_IP} $${OPENMINA_LIBP2P_PORT:+--libp2p-port $$OPENMINA_LIBP2P_PORT}"
66
ports:
77
- "3000:3000"
8-
- "8302:8302"
8+
- "${OPENMINA_LIBP2P_PORT:-8302}:${OPENMINA_LIBP2P_PORT:-8302}"
99
volumes:
1010
- ./openmina-workdir:/root/.openmina:rw
1111
environment:
1212
MINA_PRIVKEY_PASS: "${MINA_PRIVKEY_PASS:-}"
1313
COINBASE_RECEIVER: "${COINBASE_RECEIVER:-}"
1414
OPENMINA_LIBP2P_EXTERNAL_IP: "${OPENMINA_LIBP2P_EXTERNAL_IP}"
15+
OPENMINA_LIBP2P_PORT: "${OPENMINA_LIBP2P_PORT}"
1516

1617
frontend:
1718
image: openmina/frontend:${OPENMINA_FRONTEND_TAG:-latest}

docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ services:
22
openmina-node:
33
image: openmina/openmina:${OPENMINA_TAG:-latest}
44
entrypoint: >
5-
sh -c "openmina node $${OPENMINA_LIBP2P_EXTERNAL_IP:+--libp2p-external-ip $$OPENMINA_LIBP2P_EXTERNAL_IP}"
5+
sh -c "openmina node $${OPENMINA_LIBP2P_EXTERNAL_IP:+--libp2p-external-ip $$OPENMINA_LIBP2P_EXTERNAL_IP} $${OPENMINA_LIBP2P_PORT:+--libp2p-port $$OPENMINA_LIBP2P_PORT}"
66
volumes:
77
- ./openmina-workdir:/root/.openmina:rw
88
ports:
99
- "3000:3000"
10-
- "8302:8302"
10+
- "${OPENMINA_LIBP2P_PORT:-8302}:${OPENMINA_LIBP2P_PORT:-8302}"
1111
environment:
1212
OPENMINA_LIBP2P_EXTERNAL_IP: "${OPENMINA_LIBP2P_EXTERNAL_IP}"
13+
OPENMINA_LIBP2P_PORT: "${OPENMINA_LIBP2P_PORT}"
1314

1415
frontend:
1516
image: openmina/frontend:${OPENMINA_FRONTEND_TAG:-latest}

frontend/docker/startup.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ download_circuit_files() {
2727
CIRCUITS_VERSION="3.0.1devnet"
2828

2929
DEVNET_CIRCUIT_FILES=(
30+
"block_verifier_index.postcard"
31+
"transaction_verifier_index.postcard"
3032
"step-step-proving-key-blockchain-snark-step-0-55f640777b6486a6fd3fdbc3fcffcc60_gates.json"
3133
"step-step-proving-key-blockchain-snark-step-0-55f640777b6486a6fd3fdbc3fcffcc60_internal_vars.bin"
3234
"step-step-proving-key-blockchain-snark-step-0-55f640777b6486a6fd3fdbc3fcffcc60_rows_rev.bin"
@@ -77,35 +79,59 @@ download_wasm_files() {
7779
echo "Error: OPENMINA_WASM_VERSION is not set. Exiting."
7880
exit 1
7981
fi
80-
82+
8183
WASM_URL="$OPENMINA_BASE_URL/openmina/releases/download/$OPENMINA_WASM_VERSION/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz"
8284
TARGET_DIR="/usr/local/apache2/htdocs/assets/webnode/pkg"
83-
85+
8486
mkdir -p "$TARGET_DIR"
8587

8688
echo "Downloading WASM files from $WASM_URL..."
8789
curl -s -L --retry 3 --retry-delay 5 -o "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" "$WASM_URL"
88-
90+
8991
if [[ $? -ne 0 ]]; then
9092
echo "Failed to download the WASM file after 3 attempts, exiting."
9193
exit 1
9294
else
9395
echo "WASM file downloaded successfully. Extracting to $TARGET_DIR..."
9496

9597
tar -xzf "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" -C "$TARGET_DIR"
96-
98+
9799
# Check if the extraction was successful
98100
if [[ $? -ne 0 ]]; then
99101
echo "Failed to extract the WASM file, exiting."
100102
exit 1
101103
else
102104
echo "WASM files extracted successfully to $TARGET_DIR"
105+
106+
# Inject caching logic into openmina_node_web.js
107+
OPENMINA_JS="$TARGET_DIR/openmina_node_web.js"
108+
inject_caching_logic "$OPENMINA_JS"
103109
fi
104110
fi
105111

106112
rm "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz"
107113
}
108114

115+
inject_caching_logic() {
116+
local js_file="$1"
117+
if [ -f "$js_file" ]; then
118+
echo "Injecting caching logic into $js_file"
119+
120+
# Generate a unique hash
121+
local hash=$(openssl rand -hex 8)
122+
123+
sed -i 's/module_or_path = fetch(module_or_path);/module_or_path = fetch(module_or_path, { cache: "force-cache", headers: { "Cache-Control": "max-age=31536000, immutable" } });/' "$js_file"
124+
if [[ $? -ne 0 ]]; then
125+
echo "Failed to inject caching logic into $js_file"
126+
else
127+
echo "Successfully injected caching logic into $js_file"
128+
fi
129+
else
130+
echo "Warning: $js_file not found. Caching logic not injected."
131+
fi
132+
}
133+
134+
109135
if [ -n "$OPENMINA_FRONTEND_ENVIRONMENT" ]; then
110136
echo "Using environment: $OPENMINA_FRONTEND_ENVIRONMENT"
111137
cp -f /usr/local/apache2/htdocs/assets/environments/"$OPENMINA_FRONTEND_ENVIRONMENT".js \

frontend/httpd.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,20 @@ SSLProxyEngine On
228228
</Location>
229229

230230
<IfModule unixd_module>
231+
232+
# Cache rules for WebNode assets
233+
<LocationMatch "/assets/webnode/pkg/openmina_node_web\.js">
234+
Header set Cache-Control "public, max-age=31536000, immutable"
235+
</LocationMatch>
236+
<LocationMatch "/assets/webnode/pkg/openmina_node_web_bg\.wasm">
237+
Header set Cache-Control "public, max-age=31536000, immutable"
238+
</LocationMatch>
239+
240+
# Make sure mod_headers is enabled
241+
<IfModule !mod_headers.c>
242+
LoadModule headers_module modules/mod_headers.so
243+
</IfModule>
244+
231245
#
232246
# If you wish httpd to run as a different user or group, you must run
233247
# httpd as root initially and it will switch.

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
"install:deps": "npm install",
66
"start": "npm install && ng serve --configuration local --open",
77
"start:dev": "ng serve --configuration development",
8+
"start:dev:mobile": "ng serve --configuration development --host 0.0.0.0",
89
"build": "ng build",
910
"build:prod": "ng build --configuration production",
1011
"tests": "npx cypress open --config baseUrl=http://localhost:4200",
1112
"tests:headless": "npx cypress run --headless --config baseUrl=http://localhost:4200",
1213
"docker": "npm run build:prod && docker buildx build --platform linux/amd64 -t openmina/frontend:latest . && docker push openmina/frontend:latest",
13-
"start:bundle": "npx http-server dist/frontend -p 4200"
14+
"start:bundle": "npx http-server dist/frontend -p 4200",
15+
"prebuild": "node scripts/update-webnode-version.js"
1416
},
1517
"private": true,
1618
"dependencies": {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs = require('fs');
2+
const crypto = require('crypto');
3+
4+
// Generate a random hash
5+
const hash = crypto.randomBytes(16).toString('hex'); // Generates a 32-character random hex string
6+
7+
// Read and update index.html
8+
const indexPath = './src/index.html';
9+
let indexHtml = fs.readFileSync(indexPath, 'utf8');
10+
11+
// Enhanced Regex Pattern
12+
// Match 'const WEBNODE_VERSION = ' with optional whitespace around the equals and between quotes
13+
const versionRegex = /const\s+WEBNODE_VERSION\s*=\s*['"][^'"]*['"];/;
14+
15+
// Perform replacement
16+
indexHtml = indexHtml.replace(versionRegex, `const WEBNODE_VERSION = '${hash}';`);
17+
18+
// Write updated content to index.html
19+
fs.writeFileSync(indexPath, indexHtml);
20+
21+
console.log(`Updated WEBNODE_VERSION in ${indexPath} to ${hash}`);

0 commit comments

Comments
 (0)