Skip to content

Commit

Permalink
[bitcoin_move] Improve reorg and pending block (#2691)
Browse files Browse the repository at this point in the history
* [bitcoin] Improve relayer and pending block

* [rpc] Provide rooch_status API
  • Loading branch information
jolestar authored Sep 25, 2024
1 parent d5de261 commit 3f30c9b
Show file tree
Hide file tree
Showing 24 changed files with 571 additions and 80 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions crates/rooch-event/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ impl Handler<GasUpgradeMessage> for EventActor {
}

#[derive(Default, Clone, Debug)]
pub struct ServiceStatusMessage {
pub struct UpdateServiceStatusMessage {
pub status: ServiceStatus,
}

impl Message for ServiceStatusMessage {
impl Message for UpdateServiceStatusMessage {
type Result = anyhow::Result<()>;
}

#[async_trait]
impl Handler<ServiceStatusMessage> for EventActor {
impl Handler<UpdateServiceStatusMessage> for EventActor {
async fn handle(
&mut self,
message: ServiceStatusMessage,
message: UpdateServiceStatusMessage,
_ctx: &mut ActorContext,
) -> anyhow::Result<()> {
log::debug!("EventActor receive message {:?}", message);
Expand Down
12 changes: 8 additions & 4 deletions crates/rooch-executor/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,16 @@ impl ExecutorProxy {
.await?
}

/// Get latest root object
pub async fn get_root(&self) -> Result<ObjectState> {
self.actor
.send(crate::actor::messages::GetRootMessage {})
.await?
}

// This is a workaround function to sync the state of the executor to reader
pub async fn sync_state(&self) -> Result<()> {
let root = self
.actor
.send(crate::actor::messages::GetRootMessage {})
.await??;
let root = self.get_root().await?;
self.refresh_state(root.metadata, false).await
}

Expand Down
189 changes: 189 additions & 0 deletions crates/rooch-open-rpc-spec/schemas/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,18 @@
}
}
},
{
"name": "rooch_status",
"description": "Get the chain and service status",
"params": [],
"result": {
"name": "Status",
"required": true,
"schema": {
"$ref": "#/components/schemas/Status"
}
}
},
{
"name": "rooch_syncStates",
"description": "Sync state change sets",
Expand Down Expand Up @@ -788,6 +800,32 @@
],
"components": {
"schemas": {
"AccumulatorInfoView": {
"type": "object",
"required": [
"accumulator_root",
"frozen_subtree_roots",
"num_leaves",
"num_nodes"
],
"properties": {
"accumulator_root": {
"$ref": "#/components/schemas/primitive_types::H256"
},
"frozen_subtree_roots": {
"type": "array",
"items": {
"$ref": "#/components/schemas/primitive_types::H256"
}
},
"num_leaves": {
"$ref": "#/components/schemas/u64"
},
"num_nodes": {
"$ref": "#/components/schemas/u64"
}
}
},
"AnnotatedFunctionResultView": {
"type": "object",
"required": [
Expand Down Expand Up @@ -940,6 +978,46 @@
}
}
},
"BitcoinStatus": {
"type": "object",
"properties": {
"confirmed_block": {
"anyOf": [
{
"$ref": "#/components/schemas/BlockHeightHashView"
},
{
"type": "null"
}
]
},
"pending_block": {
"anyOf": [
{
"$ref": "#/components/schemas/BlockHeightHashView"
},
{
"type": "null"
}
]
}
}
},
"BlockHeightHashView": {
"type": "object",
"required": [
"block_hash",
"block_height"
],
"properties": {
"block_hash": {
"type": "string"
},
"block_height": {
"$ref": "#/components/schemas/u64"
}
}
},
"DisplayFieldsView": {
"type": "object",
"required": [
Expand Down Expand Up @@ -2709,6 +2787,36 @@
}
]
},
"RoochStatus": {
"type": "object",
"required": [
"root_state",
"sequencer_info"
],
"properties": {
"root_state": {
"$ref": "#/components/schemas/RootStateView"
},
"sequencer_info": {
"$ref": "#/components/schemas/SequencerInfoView"
}
}
},
"RootStateView": {
"type": "object",
"required": [
"size",
"state_root"
],
"properties": {
"size": {
"$ref": "#/components/schemas/u64"
},
"state_root": {
"$ref": "#/components/schemas/primitive_types::H256"
}
}
},
"SatPointView": {
"type": "object",
"required": [
Expand Down Expand Up @@ -2749,6 +2857,53 @@
}
}
},
"SequencerInfoView": {
"type": "object",
"required": [
"last_accumulator_info",
"last_order"
],
"properties": {
"last_accumulator_info": {
"$ref": "#/components/schemas/AccumulatorInfoView"
},
"last_order": {
"$ref": "#/components/schemas/u64"
}
}
},
"ServiceStatus": {
"oneOf": [
{
"description": "The service is active and running normally.",
"type": "string",
"enum": [
"active"
]
},
{
"description": "The service is in maintenance mode.",
"type": "string",
"enum": [
"maintenance"
]
},
{
"description": "The service is in read-only mode.",
"type": "string",
"enum": [
"read-only-mode"
]
},
{
"description": "The service is in date import mode.",
"type": "string",
"enum": [
"date-import-mode"
]
}
]
},
"SpecificStructView": {
"description": "Some specific struct that we want to display in a special way for better readability",
"anyOf": [
Expand Down Expand Up @@ -2842,6 +2997,40 @@
}
}
},
"Status": {
"type": "object",
"required": [
"bitcoin_status",
"rooch_status",
"service_status"
],
"properties": {
"bitcoin_status": {
"description": "The status of the Bitcoin chain",
"allOf": [
{
"$ref": "#/components/schemas/BitcoinStatus"
}
]
},
"rooch_status": {
"description": "The status of the Rooch chain",
"allOf": [
{
"$ref": "#/components/schemas/RoochStatus"
}
]
},
"service_status": {
"description": "The status of the rpc service",
"allOf": [
{
"$ref": "#/components/schemas/ServiceStatus"
}
]
}
}
},
"SyncStateFilterView": {
"oneOf": [
{
Expand Down
12 changes: 10 additions & 2 deletions crates/rooch-pipeline-processor/src/actor/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

use anyhow::Result;
use coerce::actor::message::Message;
use rooch_types::transaction::{
ExecuteTransactionResponse, L1BlockWithBody, L1Transaction, RoochTransaction,
use rooch_types::{
service_status::ServiceStatus,
transaction::{ExecuteTransactionResponse, L1BlockWithBody, L1Transaction, RoochTransaction},
};

#[derive(Clone)]
Expand Down Expand Up @@ -33,3 +34,10 @@ pub struct ExecuteL1TxMessage {
impl Message for ExecuteL1TxMessage {
type Result = Result<ExecuteTransactionResponse>;
}

#[derive(Clone)]
pub struct GetServiceStatusMessage {}

impl Message for GetServiceStatusMessage {
type Result = Result<ServiceStatus>;
}
Loading

0 comments on commit 3f30c9b

Please sign in to comment.