Skip to content

Commit

Permalink
(#85) Network Viewer - Write Sui events in SQLite in-memory DB
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Jan 11, 2024
1 parent c105bb5 commit 4d444a1
Show file tree
Hide file tree
Showing 20 changed files with 1,235 additions and 1,755 deletions.
1,729 changes: 130 additions & 1,599 deletions rust/demo-app/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rust/demo-app/crates/demo/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub async fn count() -> Result<(), anyhow::Error> {

let signature = keystore.sign_secure(&client_address, &move_call, Intent::sui_transaction())?;

let tx = Transaction::from_data(move_call, Intent::sui_transaction(), vec![signature]);
let tx = Transaction::from_data(move_call, vec![signature]);
let response = sui_client
.quorum_driver_api()
.execute_transaction_block(
Expand Down
4 changes: 2 additions & 2 deletions rust/demo-app/move/sources/counter.move
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module demo::Counter {

public(friend) fun inc(self: &mut Counter, console: &Console, ctx: &TxContext)
{
console.debug(b"inc called");
console.debug(b"internal inc() called");

self.count = self.count + 1;

Expand All @@ -68,7 +68,7 @@ module demo::Counter {
log::console::set_log_level(&mut console, log::consts::Info());

// Log a message.
console.info(b"increment() entry");
console.info(b"increment() entry called");

// No check of the sender. Anyone can increment the counter.
demo::Counter::inc(self, &console, ctx);
Expand Down
28 changes: 22 additions & 6 deletions rust/helper/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions rust/suibase/crates/suibase-daemon/src/admin_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl AdminController {
// Forward the message to the ShellWorker.
let mut worker_msg = GenericChannelMsg::new();
worker_msg.event_id = EVENT_EXEC;
worker_msg.data_string = msg.data_string;
worker_msg.command = msg.data_string;
worker_msg.workdir_idx = msg.workdir_idx;
worker_msg.resp_channel = msg.resp_channel;
shell_worker_tx.send(worker_msg).await.unwrap();
Expand Down Expand Up @@ -465,12 +465,15 @@ impl AdminController {
{
let (events_writer_worker_tx, events_writer_worker_rx) =
tokio::sync::mpsc::channel(100);
wd_tracking.events_writer_worker_tx = Some(events_writer_worker_tx);

let events_writer_worker_params = EventsWriterWorkerParams::new(
self.globals.clone(),
events_writer_worker_rx,
events_writer_worker_tx.clone(),
workdir_idx,
);
wd_tracking.events_writer_worker_tx = Some(events_writer_worker_tx);

let events_writer_worker = EventsWriterWorker::new(events_writer_worker_params);
let nested = subsys.start(SubsystemBuilder::new("events-writer-worker", |a| {
events_writer_worker.run(a)
Expand Down Expand Up @@ -527,11 +530,11 @@ impl AdminController {

match self.event_loop(&subsys).cancel_on_shutdown(&subsys).await {
Ok(()) => {
log::info!("shutting down - normal exit (2)");
log::info!("normal thread exit (2)");
Ok(())
}
Err(_cancelled_by_shutdown) => {
log::info!("shutting down - normal exit (1)");
log::info!("normal thread exit (1)");
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions rust/suibase/crates/suibase-daemon/src/api/api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ impl Runnable<APIServerParams> for APIServerThread {

match self.event_loop(&subsys).cancel_on_shutdown(&subsys).await {
Ok(_) => {
log::info!("shutting down - normal exit (2)");
log::info!("normal thread exit (2)");
Ok(())
}
Err(_cancelled_by_shutdown) => {
log::info!("shutting down - normal exit (1)");
log::info!("normal thread exit (1)");
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/suibase/crates/suibase-daemon/src/api/def_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl SuiObjectInstance {
#[derive(Clone, Debug, JsonSchema, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct PackageInstance {
pub package_id: String,
pub package_id: String, // Hexa (no 0x).
pub package_name: String,
pub package_timestamp: String,
pub init_objects: Option<Vec<SuiObjectInstance>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ impl<Thread: Runnable<Parameter> + Send + 'static, Parameter: Send + Clone> Runn
break;
}

log::info!("{} restarting...", inner_thread_name);
// Make an exception to not display "WebSocketWorker" restart
// because they normally restart every ~30 seconds because of
// "normal" connection closing from many public servers.
if self.name != "WebSocketWorker" {
log::info!("{} restarting...", inner_thread_name);
}
}
log::info!("{} shutting down - normal exit", outer_thread_name);
log::info!("{} normal thread exit", outer_thread_name);
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ use rusqlite::Connection;

// Generic DBTable.
pub trait DBTable {
fn create_table(conn: &Connection) -> rusqlite::Result<()>;
fn create_table(
conn: &Connection,
workdir_name: String, // Always prepended to table_name.
namespace: Option<String>, // Optional. Always prepended to table name.
name_suffix: Option<String>, // Optional. Sometimes appended to table name (ignored with table targeted by foreign key).
) -> rusqlite::Result<()>;
}

// Can have its Versioned<T> JSON data persisted in a DB table.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// Some common types depending only on built-in or "standard" types.
pub type EpochTimestamp = tokio::time::Instant;

// Event Level (matches consts used in the Suibase log Move module)
pub type EventLevel = u8;
pub const EVENT_LEVEL_INVALID: u8 = 0u8;
pub const EVENT_LEVEL_ERROR: u8 = 1u8;
pub const EVENT_LEVEL_WARN: u8 = 2u8;
pub const EVENT_LEVEL_INFO: u8 = 3u8;
pub const EVENT_LEVEL_DEBUG: u8 = 4u8;
pub const EVENT_LEVEL_TRACE: u8 = 5u8;
pub const EVENT_LEVEL_MIN: u8 = EVENT_LEVEL_ERROR;
pub const EVENT_LEVEL_MAX: u8 = EVENT_LEVEL_TRACE;

/*
use std::sync::atomic::{AtomicUsize, Ordering};
Expand Down Expand Up @@ -39,12 +50,16 @@ pub type GenericRx = tokio::sync::mpsc::Receiver<GenericChannelMsg>;
pub type GenericChannelEventID = u8;
pub const EVENT_AUDIT: u8 = 1; // Fast consistency check. Globals read-only access. Should emit an EVENT_UPDATE to self for globals update.
pub const EVENT_UPDATE: u8 = 2; // Apply Globals config changes and/or update status. Globals write access allowed.
pub const EVENT_EXEC: u8 = 3; // Execute what is specified by the params. Globals write access allowed.
pub const EVENT_EXEC: u8 = 3; // Execute what is specified by the params (command, data_string...). Globals write access allowed.

pub struct GenericChannelMsg {
pub event_id: GenericChannelEventID,

// Params
pub data_string: Option<String>,
pub command: Option<String>,
pub params: Vec<String>,

pub data_json: Option<serde_json::Value>,
pub workdir_idx: Option<WorkdirIdx>,

// Optional channel to send a one-time response.
Expand All @@ -55,13 +70,20 @@ impl GenericChannelMsg {
pub fn new() -> Self {
Self {
event_id: 0,
data_string: None,
command: None,
params: Vec::new(),
data_json: None,
workdir_idx: None,
resp_channel: None,
}
}
pub fn data_string(&self) -> Option<String> {
self.data_string.clone()

pub fn command(&self) -> Option<String> {
self.command.clone()
}

pub fn params(&self, index: usize) -> Option<String> {
self.params.get(index).cloned()
}

pub fn workdir_idx(&self) -> Option<WorkdirIdx> {
Expand All @@ -73,7 +95,8 @@ impl std::fmt::Debug for GenericChannelMsg {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("GenericChannelMsg")
.field("event_id", &self.event_id)
.field("data_string", &self.data_string)
.field("command", &self.command)
.field("params", &self.params)
.field("workdir_idx", &self.workdir_idx)
.finish()
}
Expand Down
4 changes: 2 additions & 2 deletions rust/suibase/crates/suibase-daemon/src/clock_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ impl Runnable<ClockTriggerParams> for ClockTriggerThread {

match self.event_loop(&subsys).cancel_on_shutdown(&subsys).await {
Ok(()) => {
log::info!("shutting down - normal exit (2)");
log::info!("normal thread exit (2)");
Ok(())
}
Err(_cancelled_by_shutdown) => {
log::info!("shutting down - normal exit (1)");
log::info!("normal thread exit (1)");
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions rust/suibase/crates/suibase-daemon/src/network_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,11 @@ impl NetworkMonitor {
.await
{
Ok(()) => {
log::info!("shutting down - normal exit (2)");
log::info!("normal thread exit (2)");
Ok(())
}
Err(_cancelled_by_shutdown) => {
log::info!("shutting down - normal exit (1)");
log::info!("normal thread exit (1)");
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions rust/suibase/crates/suibase-daemon/src/workdirs_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ impl WorkdirsWatcher {
.await
{
Ok(()) => {
log::info!("shutting down - normal exit (2)");
log::info!("normal thread exit (2)");
Ok(())
}
Err(_cancelled_by_shutdown) => {
log::info!("shutting down - normal exit (1)");
log::info!("normal thread exit (1)");
Ok(())
}
}
Expand Down
Loading

0 comments on commit 4d444a1

Please sign in to comment.