Skip to content

Commit

Permalink
chore(drive): add check tx core rpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Jun 13, 2024
1 parent d0ce81e commit f5d4265
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 106 deletions.
2 changes: 1 addition & 1 deletion packages/dashmate/configs/defaults/getBaseConfigFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function getBaseConfigFactory(homeDir) {
],
lowPriority: false,
},
drive_other: {
drive_check_tx: {
password: 'rpcpassword',
whitelist: ['getrawtransaction'],
lowPriority: true,
Expand Down
12 changes: 8 additions & 4 deletions packages/dashmate/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ services:
- drive_abci_data:/var/lib/dash/rs-drive-abci/db
environment:
- CHAIN_ID=${PLATFORM_DRIVE_TENDERDASH_GENESIS_CHAIN_ID:-devnet}
- CORE_JSON_RPC_USERNAME=${CORE_RPC_USER:?err}
- CORE_JSON_RPC_PASSWORD=${CORE_RPC_PASSWORD:?err}
- CORE_JSON_RPC_HOST=core
- CORE_JSON_RPC_PORT=${CORE_RPC_PORT:?err}
- CORE_CONSENSUS_JSON_RPC_USERNAME=drive_consensus
- CORE_CONSENSUS_JSON_RPC_PASSWORD=${CORE_RPC_USERS_DRIVE_CONSENSUS_PASSWORD:?err}
- CORE_CONSENSUS_JSON_RPC_HOST=core
- CORE_CONSENSUS_JSON_RPC_PORT=${CORE_RPC_PORT:?err}
- CORE_CHECK_TX_JSON_RPC_USERNAME=drive_check_tx
- CORE_CHECK_TX_JSON_RPC_PASSWORD=${CORE_RPC_USERS_DRIVE_CHECK_TX_PASSWORD:?err}
- CORE_CHECK_TX_JSON_RPC_HOST=core
- CORE_CHECK_TX_JSON_RPC_PORT=${CORE_RPC_PORT:?err}
- DPNS_MASTER_PUBLIC_KEY=${PLATFORM_DPNS_MASTER_PUBLIC_KEY}
- DPNS_SECOND_PUBLIC_KEY=${PLATFORM_DPNS_SECOND_PUBLIC_KEY}
- DASHPAY_MASTER_PUBLIC_KEY=${PLATFORM_DASHPAY_MASTER_PUBLIC_KEY}
Expand Down
13 changes: 9 additions & 4 deletions packages/rs-drive-abci/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ DATA_CONTRACTS_BLOCK_CACHE_SIZE=200

# DashCore JSON-RPC host, port and credentials
# Read more: https://dashcore.readme.io/docs/core-api-ref-remote-procedure-calls
CORE_JSON_RPC_HOST=127.0.0.1
CORE_JSON_RPC_PORT=9998
CORE_JSON_RPC_USERNAME=dashrpc
CORE_JSON_RPC_PASSWORD=password
CORE_CONSENSUS_JSON_RPC_HOST=127.0.0.1
CORE_CONSENSUS_JSON_RPC_PORT=9998
CORE_CONSENSUS_JSON_RPC_USERNAME=dashrpc
CORE_CONSENSUS_JSON_RPC_PASSWORD=password

CORE_CHECK_TX_JSON_RPC_HOST=127.0.0.1
CORE_CHECK_TX_JSON_RPC_PORT=9998
CORE_CHECK_TX_JSON_RPC_USERNAME=dashrpc
CORE_CHECK_TX_JSON_RPC_PASSWORD=password

INITIAL_CORE_CHAINLOCKED_HEIGHT=1243

Expand Down
13 changes: 9 additions & 4 deletions packages/rs-drive-abci/.env.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ DATA_CONTRACTS_BLOCK_CACHE_SIZE=200

# DashCore JSON-RPC host, port and credentials
# Read more: https://dashcore.readme.io/docs/core-api-ref-remote-procedure-calls
CORE_JSON_RPC_HOST=127.0.0.1
CORE_JSON_RPC_PORT=9998
CORE_JSON_RPC_USERNAME=dashrpc
CORE_JSON_RPC_PASSWORD=password
CORE_CONSENSUS_JSON_RPC_HOST=127.0.0.1
CORE_CONSENSUS_JSON_RPC_PORT=9998
CORE_CONSENSUS_JSON_RPC_USERNAME=dashrpc
CORE_CONSENSUS_JSON_RPC_PASSWORD=password

CORE_CHECK_TX_JSON_RPC_HOST=127.0.0.1
CORE_CHECK_TX_JSON_RPC_PORT=9998
CORE_CHECK_TX_JSON_RPC_USERNAME=dashrpc
CORE_CHECK_TX_JSON_RPC_PASSWORD=password

INITIAL_CORE_CHAINLOCKED_HEIGHT=1243

Expand Down
13 changes: 9 additions & 4 deletions packages/rs-drive-abci/.env.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ DATA_CONTRACTS_BLOCK_CACHE_SIZE=200

# DashCore JSON-RPC host, port and credentials
# Read more: https://dashcore.readme.io/docs/core-api-ref-remote-procedure-calls
CORE_JSON_RPC_HOST=127.0.0.1
CORE_JSON_RPC_PORT=9998
CORE_JSON_RPC_USERNAME=dashrpc
CORE_JSON_RPC_PASSWORD=password
CORE_CONSENSUS_JSON_RPC_HOST=127.0.0.1
CORE_CONSENSUS_JSON_RPC_PORT=9998
CORE_CONSENSUS_JSON_RPC_USERNAME=dashrpc
CORE_CONSENSUS_JSON_RPC_PASSWORD=password

CORE_CHECK_TX_JSON_RPC_HOST=127.0.0.1
CORE_CHECK_TX_JSON_RPC_PORT=9998
CORE_CHECK_TX_JSON_RPC_USERNAME=dashrpc
CORE_CHECK_TX_JSON_RPC_PASSWORD=password

INITIAL_CORE_CHAINLOCKED_HEIGHT=1243

Expand Down
10 changes: 6 additions & 4 deletions packages/rs-drive-abci/src/abci/app/check_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ where
{
/// Platform
platform: Arc<Platform<C>>,
core_rpc: Arc<C>,
}

impl<C> PlatformApplication<C> for CheckTxAbciApplication<C>
Expand All @@ -37,8 +38,8 @@ where
C: CoreRPCLike + Send + Sync + 'static,
{
/// Create new ABCI app
pub fn new(platform: Arc<Platform<C>>) -> Self {
Self { platform }
pub fn new(platform: Arc<Platform<C>>, core_rpc: Arc<C>) -> Self {
Self { platform, core_rpc }
}
}

Expand Down Expand Up @@ -70,6 +71,7 @@ where
request: tonic::Request<proto::RequestCheckTx>,
) -> Result<tonic::Response<proto::ResponseCheckTx>, tonic::Status> {
let platform = Arc::clone(&self.platform);
let core_rpc = Arc::clone(&self.core_rpc);

let proto_request = request.into_inner();

Expand All @@ -82,8 +84,8 @@ where
};

spawn_blocking_task_with_name_if_supported(thread_name, move || {
let response =
handler::check_tx(&platform, proto_request).map_err(error_into_status)?;
let response = handler::check_tx(&platform, &core_rpc, proto_request)
.map_err(error_into_status)?;

Ok(tonic::Response::new(response))
})?
Expand Down
3 changes: 2 additions & 1 deletion packages/rs-drive-abci/src/abci/app/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ where
&self,
request: proto::RequestCheckTx,
) -> Result<proto::ResponseCheckTx, proto::ResponseException> {
handler::check_tx(self.platform, request).map_err(error_into_exception)
handler::check_tx(self.platform, &self.platform.core_rpc, request)
.map_err(error_into_exception)
}

fn extend_vote(
Expand Down
13 changes: 11 additions & 2 deletions packages/rs-drive-abci/src/abci/handler/check_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::abci::handler::error::HandlerError;
use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::metrics::{LABEL_ABCI_RESPONSE_CODE, LABEL_CHECK_TX_MODE, LABEL_STATE_TRANSITION_NAME};
use crate::platform_types::platform::Platform;
use crate::platform_types::platform::{Platform, PlatformRef};
use crate::rpc::core::CoreRPCLike;
use dpp::consensus::codes::ErrorWithCode;
use dpp::fee::SignedCredits;
Expand All @@ -13,6 +13,7 @@ use tenderdash_abci::proto::abci as proto;

pub fn check_tx<C>(
platform: &Platform<C>,
core_rpc: &C,
request: proto::RequestCheckTx,
) -> Result<proto::ResponseCheckTx, Error>
where
Expand All @@ -21,14 +22,22 @@ where
let mut timer = crate::metrics::abci_request_duration("check_tx");

let platform_state = platform.state.load();

let platform_ref = PlatformRef {
drive: &platform.drive,
state: &platform_state,
config: &platform.config,
core_rpc,
};

let platform_version = platform_state.current_platform_version()?;

let proto::RequestCheckTx { tx, r#type } = request;

let validation_result = platform.check_tx(
tx.as_slice(),
r#type.try_into()?,
&platform_state,
&platform_ref,
platform_version,
);

Expand Down
64 changes: 44 additions & 20 deletions packages/rs-drive-abci/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,76 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
use crate::logging::LogConfigs;
use crate::{abci::config::AbciConfig, error::Error};

/// Configuration for Dash Core RPC client
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CoreRpcConfig {
/// Configuration for Dash Core RPC client used in consensus logic
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct ConsensusCoreRpcConfig {
/// Core RPC client hostname or IP address
#[serde(rename = "core_json_rpc_host")]
#[serde(rename = "core_consensus_json_rpc_host")]
pub host: String,

// FIXME: fix error Configuration(Custom("invalid type: string \"9998\", expected i16")) and change port to i16
/// Core RPC client port number
#[serde(rename = "core_json_rpc_port")]
pub port: String,
#[serde(
rename = "core_consensus_json_rpc_port",
deserialize_with = "from_str_or_number"
)]
pub port: u16,

/// Core RPC client username
#[serde(rename = "core_json_rpc_username")]
#[serde(rename = "core_consensus_json_rpc_username")]
pub username: String,

/// Core RPC client password
#[serde(rename = "core_json_rpc_password")]
#[serde(rename = "core_consensus_json_rpc_password")]
pub password: String,
}

impl CoreRpcConfig {
impl ConsensusCoreRpcConfig {
/// Return core address in the `host:port` format.
pub fn url(&self) -> String {
format!("{}:{}", self.host, self.port)
}
}

impl Default for CoreRpcConfig {
fn default() -> Self {
Self {
host: String::from("127.0.0.1"),
port: String::from("1234"),
username: String::from(""),
password: String::from(""),
}
/// Configuration for Dash Core RPC client used in check tx
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct CheckTxCoreRpcConfig {
/// Core RPC client hostname or IP address
#[serde(rename = "core_check_tx_json_rpc_host")]
pub host: String,

/// Core RPC client port number
#[serde(
rename = "core_check_tx_json_rpc_port",
deserialize_with = "from_str_or_number"
)]
pub port: u16,

/// Core RPC client username
#[serde(rename = "core_check_tx_json_rpc_username")]
pub username: String,

/// Core RPC client password
#[serde(rename = "core_check_tx_json_rpc_password")]
pub password: String,
}

impl CheckTxCoreRpcConfig {
/// Return core address in the `host:port` format.
pub fn url(&self) -> String {
format!("{}:{}", self.host, self.port)
}
}

/// Configuration for Dash Core related things
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct CoreConfig {
/// Core RPC config
/// Core RPC config for consensus
#[serde(flatten)]
pub consensus_rpc: ConsensusCoreRpcConfig,
/// Core RPC config for check tx
#[serde(flatten)]
pub rpc: CoreRpcConfig,
pub check_tx_rpc: CheckTxCoreRpcConfig,
}

/// Configuration of the execution part of Dash Platform.
Expand Down
7 changes: 3 additions & 4 deletions packages/rs-drive-abci/src/execution/check_tx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::platform_types::platform::Platform;
use crate::platform_types::platform::{Platform, PlatformRef};

use crate::abci::AbciError;
use crate::platform_types::platform_state::PlatformState;
use crate::rpc::core::CoreRPCLike;
use dpp::consensus::ConsensusError;
use dpp::fee::fee_result::FeeResult;
Expand Down Expand Up @@ -93,11 +92,11 @@ where
&self,
raw_tx: &[u8],
check_tx_level: CheckTxLevel,
platform_state: &PlatformState,
platform_ref: &PlatformRef<C>,
platform_version: &PlatformVersion,
) -> Result<ValidationResult<CheckTxResult, ConsensusError>, Error> {
match platform_version.drive_abci.methods.engine.check_tx {
0 => self.check_tx_v0(raw_tx, check_tx_level, platform_state, platform_version),
0 => self.check_tx_v0(raw_tx, check_tx_level, platform_ref, platform_version),
version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
method: "check_tx".to_string(),
known_versions: vec![0],
Expand Down
Loading

0 comments on commit f5d4265

Please sign in to comment.