Skip to content

Commit 0a1a76d

Browse files
authored
Update RPC to use valid hash/height (#126)
1 parent ee91ef6 commit 0a1a76d

File tree

7 files changed

+20
-125
lines changed

7 files changed

+20
-125
lines changed

helm/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extraEnvVarsSecret: ""
4141

4242
## @param replicaCount Number of Polybase replicas
4343
##
44-
replicaCount: 1
44+
replicaCount: 3
4545
## @param updateStrategy.type updateStrategy for Polybase statefulset
4646
## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies
4747
##

polybase/src/db.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::hash;
22
use crate::mempool::Mempool;
3-
use crate::rollup::Rollup;
43
use crate::txn::{self, CallTxn};
54
use crate::util;
65
use futures::TryStreamExt;
@@ -87,8 +86,6 @@ impl Default for DbConfig {
8786
pub struct Db {
8887
mempool: Mempool<[u8; 32], CallTxn, usize, [u8; 32]>,
8988
gateway: Gateway,
90-
// TODO: remove this pub
91-
pub rollup: Rollup,
9289
indexer: Indexer,
9390
sender: AsyncMutex<mpsc::Sender<CallTxn>>,
9491
receiver: AsyncMutex<mpsc::Receiver<CallTxn>>,
@@ -107,7 +104,6 @@ impl Db {
107104

108105
Ok(Self {
109106
mempool: Mempool::new(),
110-
rollup: Rollup::new(),
111107
gateway: gateway::initialize(logger.clone()),
112108
indexer,
113109
sender: AsyncMutex::new(sender),

polybase/src/errors/http.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use serde::Serialize;
66
use std::{error::Error, fmt::Display};
77

88
use super::reason::ReasonCode;
9-
use crate::rollup;
109
use crate::{
1110
auth,
1211
db::{self},
@@ -185,9 +184,3 @@ impl From<auth::AuthUserError> for HTTPError {
185184
HTTPError::new(ReasonCode::from_auth_error(&err), Some(Box::new(err)))
186185
}
187186
}
188-
189-
impl From<rollup::RollupError> for HTTPError {
190-
fn from(err: rollup::RollupError) -> Self {
191-
HTTPError::new(ReasonCode::Internal, Some(Box::new(err)))
192-
}
193-
}

polybase/src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ mod errors;
1313
mod hash;
1414
mod mempool;
1515
mod network;
16-
mod rollup;
1716
mod rpc;
1817
mod txn;
1918
mod util;
@@ -258,7 +257,7 @@ async fn main() -> Result<()> {
258257
let mut last_commit = Instant::now();
259258

260259
// For migration only, check if DB is empty
261-
if db.is_empty().await.unwrap_or(true) {
260+
if db.is_empty().await.unwrap_or(true) && solid.height() == 0 {
262261
info!(logger, "DB is empty, requesting snapshot");
263262
network
264263
.send_all(NetworkEvent::SnapshotRequest {
@@ -337,8 +336,6 @@ async fn main() -> Result<()> {
337336
// We've been offered a snapshot from another peer, we should accept this offer if we
338337
// don't already have an ongoing snapshot in progress
339338
NetworkEvent::SnapshotOffer{ id } => {
340-
info!(logger, "Peer offered snapshot, sending accept"; "peer_id" => peer_id.prefix());
341-
342339
if snapshot_from.is_some() {
343340
debug!(logger, "Already have snapshot in progress, ignoring offer"; "peer_id" => peer_id.prefix(), "id" => id);
344341
continue;
@@ -349,6 +346,8 @@ async fn main() -> Result<()> {
349346
continue;
350347
}
351348

349+
info!(logger, "Peer offered snapshot, sending accept"; "peer_id" => peer_id.prefix(), "id" => id);
350+
352351
// Save who the snapshot is from
353352
snapshot_from = Some((network_peer_id.clone(), id));
354353

@@ -428,20 +427,21 @@ async fn main() -> Result<()> {
428427
#[allow(clippy::unwrap_used)]
429428
db.restore_chunk(chunk).unwrap();
430429
} else {
431-
// Reset snapshot from
432-
snapshot_from = None;
433-
434430
// We are finished, reset solid with the new proposal state from the snapshot
435431
#[allow(clippy::unwrap_used)]
436432
let manifest = db.get_manifest().await.unwrap().unwrap();
433+
let height = manifest.height;
437434
solid.reset(manifest);
438435

439-
info!(logger, "Restore db from snapshot complete");
436+
// Reset snapshot from
437+
snapshot_from = None;
438+
439+
info!(logger, "Restore db from snapshot complete"; "height" => height);
440440
}
441441
}
442442

443443
NetworkEvent::Accept { accept } => {
444-
info!(logger, "Received accept"; "height" => &accept.height, "skips" => &accept.skips, "from" => &accept.leader_id.prefix(), "hash" => accept.proposal_hash.to_string());
444+
info!(logger, "Received accept"; "height" => &accept.height, "skips" => &accept.skips, "from" => &accept.leader_id.prefix(), "hash" => accept.proposal_hash.to_string(), "local_height" => solid.height());
445445
solid.receive_accept(&accept, &peer_id);
446446
}
447447

polybase/src/rollup.rs

Lines changed: 0 additions & 101 deletions
This file was deleted.

polybase/src/rpc.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,23 @@ async fn health(state: web::Data<RouteState>) -> impl Responder {
413413
struct StatusResponse {
414414
status: String,
415415
root: String,
416+
height: usize,
416417
peers: usize,
417-
leader: usize,
418418
}
419419

420420
#[get("/v0/status")]
421421
async fn status(state: web::Data<RouteState>) -> Result<web::Json<StatusResponse>, HTTPError> {
422+
let manifest = state.db.get_manifest().await?;
423+
let height = manifest.as_ref().map(|m| m.height).unwrap_or(0);
424+
let hash = manifest
425+
.as_ref()
426+
.map(|m| m.hash().to_string())
427+
.unwrap_or("0x0".to_string());
422428
Ok(web::Json(StatusResponse {
423429
status: "OK".to_string(),
424-
root: hex::encode(state.db.rollup.root()?),
430+
root: hash,
431+
height,
425432
peers: 23,
426-
leader: 12,
427433
}))
428434
}
429435

solid/src/solid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ impl Solid {
109109
);
110110
let mut events = self.shared.events.lock();
111111
events.clear();
112+
self.reset_skip_timeout();
112113
}
113114

114115
pub fn run(&self) -> tokio::task::JoinHandle<()> {

0 commit comments

Comments
 (0)