Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
18001f6
Introduce on_open_block
remagpie Nov 26, 2019
3c8d9f0
Implement TrieDB::is_complete
remagpie Nov 7, 2019
1dff7e2
Add complete_register to ConsensusEngine
foriequal0 Nov 19, 2019
fc6a3de
Change waitNodeUntilTerm to return TermMetadata
foriequal0 Nov 20, 2019
80e6282
Refactor rpc startup code
remagpie Nov 20, 2019
74c46d6
Refactor send status function
foriequal0 Dec 3, 2019
ec0ef2b
Remove unnecessary cloning in block sync
foriequal0 Dec 3, 2019
06b3f97
Enhance error message in waitForTermChange
foriequal0 Nov 20, 2019
3b9c388
Add term_params to Metadata
foriequal0 Nov 26, 2019
5c64737
Snapshot term_metadata on every term close for the era > 0
foriequal0 Nov 26, 2019
7fba4f5
Update the era with the value in current block's state
remagpie Dec 3, 2019
9a6ec55
Read term_params from the snapshot
foriequal0 Nov 26, 2019
1101c5b
Precalculate the fee in era=1
remagpie Nov 27, 2019
1051665
Remove outdated snapshot module
foriequal0 Oct 31, 2019
f718e4a
Add configuration option for the snapshot sync target
remagpie Nov 6, 2019
b3e2238
Decide the sync extension's state with the snapshot target
remagpie Nov 7, 2019
1b785d9
Implement Snapshot & Restore modules
foriequal0 Nov 4, 2019
403b519
Fetch snapshot header from peers
remagpie Nov 12, 2019
f4af598
Make the snapshot header importable without parent
remagpie Nov 14, 2019
be35914
Update snapshot message format
remagpie Nov 5, 2019
a8627c2
Import only desired bootstrap headers
remagpie Nov 15, 2019
ecdaa3a
Implement snapshot service
foriequal0 Dec 6, 2019
27e3c4e
Add RPC devel_snapshot
foriequal0 Nov 15, 2019
ef1a176
Add basic e2e test for snapshot
foriequal0 Nov 18, 2019
b3cc277
Rename total_score to nonce in sync message
remagpie Nov 14, 2019
443a178
Add SnapshotNotifySender to Tendermint worker
foriequal0 Nov 18, 2019
4e5ba6b
Implement snapshot on term end
foriequal0 Nov 19, 2019
7490d25
Add snapshot sync test with Tendermint dynamic validator
foriequal0 Dec 6, 2019
6d5af4d
Send and receive snapshot chunk requests
remagpie Nov 18, 2019
fe9c785
Serve snapshot responses to peers
remagpie Nov 18, 2019
ef3ad4f
Use binding for match clause
remagpie Nov 19, 2019
cbe8322
Add RPC snapshot_getList
remagpie Nov 20, 2019
af90610
Add autoremoving expired snapshot feature
foriequal0 Nov 19, 2019
a96282d
Detect bootstrap header in tendermint worker
remagpie Nov 22, 2019
cc236fd
Add sync state SnapshotBody
remagpie Nov 21, 2019
0ba5323
Move to SnapshotBody state after downloading the snapthot header
remagpie Nov 21, 2019
abe60a3
Import snapshot block with body
remagpie Nov 21, 2019
9354d8d
Update the best block after importing snapshot chunks
remagpie Nov 25, 2019
eb6b204
Refactor block::Extension::transtition_to_full()
foriequal0 Dec 4, 2019
afcf587
Change sync extension to update pivot after transitioning to Full
foriequal0 Dec 4, 2019
0c598ce
Fix to receive peer requests from just connected nodes
foriequal0 Dec 3, 2019
2877685
Defer sending peer status after transitioning to full sync mode
foriequal0 Dec 3, 2019
d8368c5
Factor out snapshot notify
foriequal0 Dec 2, 2019
9ce70ad
Move send_snapshot_notify() before the early return
foriequal0 Dec 4, 2019
ed78493
Defer snapshot timing by one block in Tendermint
foriequal0 Dec 2, 2019
d925fec
Fix snapshot block estimation in test
foriequal0 Dec 4, 2019
18f8fa7
Introduce CurrentValidators
remagpie Dec 6, 2019
275a671
Get tendermint validators with CurrentValidators
remagpie Dec 6, 2019
f192340
Generate snapshot chunks for shard level state
remagpie Dec 12, 2019
8a428cb
Refactor on_chunk_response
remagpie Dec 13, 2019
f628350
Refactor sync state transition
remagpie Dec 13, 2019
364fa18
Import shard trie chunks in sync extension
remagpie Dec 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions codechain/codechain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ args:
takes_value: true
conflicts_with:
- no-discovery
- snapshot-hash:
long: snapshot-hash
value_name: HASH
requires: snapshot-number
takes_value: true
- snapshot-number:
long: snapshot-number
value_name: NUM
requires: snapshot-hash
takes_value: true
- no-snapshot:
long: no-snapshot
help: Disable snapshots
Expand Down
20 changes: 20 additions & 0 deletions codechain/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use cidr::IpCidr;
use ckey::PlatformAddress;
use clap;
use cnetwork::{FilterEntry, NetworkConfig, SocketAddr};
use primitives::H256;
use toml;

pub use self::chain_type::ChainType;
Expand Down Expand Up @@ -274,6 +275,8 @@ pub struct Network {
pub min_peers: Option<usize>,
pub max_peers: Option<usize>,
pub sync: Option<bool>,
pub snapshot_hash: Option<H256>,
pub snapshot_number: Option<u64>,
pub transaction_relay: Option<bool>,
pub discovery: Option<bool>,
pub discovery_type: Option<String>,
Expand Down Expand Up @@ -313,6 +316,8 @@ fn default_enable_devel_api() -> bool {
pub struct Snapshot {
pub disable: Option<bool>,
pub path: Option<String>,
// Snapshot's age in blocks
pub expiration: Option<u64>,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -575,6 +580,12 @@ impl Network {
if other.sync.is_some() {
self.sync = other.sync;
}
if other.snapshot_hash.is_some() {
self.snapshot_hash = other.snapshot_hash;
}
if other.snapshot_number.is_some() {
self.snapshot_number = other.snapshot_number;
}
if other.transaction_relay.is_some() {
self.transaction_relay = other.transaction_relay;
}
Expand Down Expand Up @@ -627,6 +638,12 @@ impl Network {
if matches.is_present("no-sync") {
self.sync = Some(false);
}
if let Some(snapshot_hash) = matches.value_of("snapshot-hash") {
self.snapshot_hash = Some(snapshot_hash.parse().map_err(|_| "Invalid snapshot-hash")?);
}
if let Some(snapshot_number) = matches.value_of("snapshot-number") {
self.snapshot_number = Some(snapshot_number.parse().map_err(|_| "Invalid snapshot-number")?);
}
if matches.is_present("no-tx-relay") {
self.transaction_relay = Some(false);
}
Expand Down Expand Up @@ -739,6 +756,9 @@ impl Snapshot {
if other.path.is_some() {
self.path = other.path.clone();
}
if other.expiration.is_some() {
self.expiration = other.expiration;
}
}

pub fn overwrite_with(&mut self, matches: &clap::ArgMatches) -> Result<(), String> {
Expand Down
1 change: 1 addition & 0 deletions codechain/config/presets/config.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ max_connections = 100
[snapshot]
disable = false
path = "snapshot"
expiration = 100000 # blocks. About a week

[stratum]
disable = false
Expand Down
1 change: 1 addition & 0 deletions codechain/config/presets/config.prod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ max_connections = 100
[snapshot]
disable = true
path = "snapshot"
expiration = 100000 # blocks. About a week

[stratum]
disable = true
Expand Down
71 changes: 25 additions & 46 deletions codechain/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::io;
use std::net::SocketAddr;

use crate::config::Config;
use crate::rpc_apis;
use crpc::{
jsonrpc_core, start_http, start_ipc, start_ws, HttpServer, IpcServer, MetaIoHandler, Middleware, WsError, WsServer,
Expand All @@ -33,38 +33,27 @@ pub struct RpcHttpConfig {
}

pub fn rpc_http_start(
cfg: RpcHttpConfig,
enable_devel_api: bool,
deps: &rpc_apis::ApiDependencies,
server: MetaIoHandler<(), impl Middleware<()>>,
config: RpcHttpConfig,
) -> Result<HttpServer, String> {
let url = format!("{}:{}", cfg.interface, cfg.port);
let url = format!("{}:{}", config.interface, config.port);
let addr = url.parse().map_err(|_| format!("Invalid JSONRPC listen host/port given: {}", url))?;
let server = setup_http_rpc_server(&addr, cfg.cors.clone(), cfg.hosts.clone(), enable_devel_api, deps)?;
cinfo!(RPC, "RPC Listening on {}", url);
if let Some(hosts) = cfg.hosts {
cinfo!(RPC, "Allowed hosts are {:?}", hosts);
}
if let Some(cors) = cfg.cors {
cinfo!(RPC, "CORS domains are {:?}", cors);
}
Ok(server)
}

fn setup_http_rpc_server(
url: &SocketAddr,
cors_domains: Option<Vec<String>>,
allowed_hosts: Option<Vec<String>>,
enable_devel_api: bool,
deps: &rpc_apis::ApiDependencies,
) -> Result<HttpServer, String> {
let server = setup_rpc_server(enable_devel_api, deps);
let start_result = start_http(url, cors_domains, allowed_hosts, server);
let start_result = start_http(&addr, config.cors.clone(), config.hosts.clone(), server);
match start_result {
Err(ref err) if err.kind() == io::ErrorKind::AddrInUse => {
Err(format!("RPC address {} is already in use, make sure that another instance of a CodeChain node is not running or change the address using the --jsonrpc-port option.", url))
},
Err(e) => Err(format!("RPC error: {:?}", e)),
Ok(server) => Ok(server),
Ok(server) => {
cinfo!(RPC, "RPC Listening on {}", url);
if let Some(hosts) = config.hosts {
cinfo!(RPC, "Allowed hosts are {:?}", hosts);
}
if let Some(cors) = config.cors {
cinfo!(RPC, "CORS domains are {:?}", cors);
}
Ok(server)
},
}
}

Expand All @@ -74,19 +63,17 @@ pub struct RpcIpcConfig {
}

pub fn rpc_ipc_start(
cfg: &RpcIpcConfig,
enable_devel_api: bool,
deps: &rpc_apis::ApiDependencies,
server: MetaIoHandler<(), impl Middleware<()>>,
config: RpcIpcConfig,
) -> Result<IpcServer, String> {
let server = setup_rpc_server(enable_devel_api, deps);
let start_result = start_ipc(&cfg.socket_addr, server);
let start_result = start_ipc(&config.socket_addr, server);
match start_result {
Err(ref err) if err.kind() == io::ErrorKind::AddrInUse => {
Err(format!("IPC address {} is already in use, make sure that another instance of a Codechain node is not running or change the address using the --ipc-path options.", cfg.socket_addr))
Err(format!("IPC address {} is already in use, make sure that another instance of a Codechain node is not running or change the address using the --ipc-path options.", config.socket_addr))
},
Err(e) => Err(format!("IPC error: {:?}", e)),
Ok(server) => {
cinfo!(RPC, "IPC Listening on {}", cfg.socket_addr);
cinfo!(RPC, "IPC Listening on {}", config.socket_addr);
Ok(server)
},
}
Expand All @@ -99,15 +86,10 @@ pub struct RpcWsConfig {
pub max_connections: usize,
}

pub fn rpc_ws_start(
cfg: &RpcWsConfig,
enable_devel_api: bool,
deps: &rpc_apis::ApiDependencies,
) -> Result<WsServer, String> {
let server = setup_rpc_server(enable_devel_api, deps);
let url = format!("{}:{}", cfg.interface, cfg.port);
pub fn rpc_ws_start(server: MetaIoHandler<(), impl Middleware<()>>, config: RpcWsConfig) -> Result<WsServer, String> {
let url = format!("{}:{}", config.interface, config.port);
let addr = url.parse().map_err(|_| format!("Invalid WebSockets listen host/port given: {}", url))?;
let start_result = start_ws(&addr, server, cfg.max_connections);
let start_result = start_ws(&addr, server, config.max_connections);
match start_result {
Err(WsError::Io(ref err)) if err.kind() == io::ErrorKind::AddrInUse => {
Err(format!("WebSockets address {} is already in use, make sure that another instance of a Codechain node is not running or change the address using the --ws-port options.", addr))
Expand All @@ -120,12 +102,9 @@ pub fn rpc_ws_start(
}
}

fn setup_rpc_server(
enable_devel_api: bool,
deps: &rpc_apis::ApiDependencies,
) -> MetaIoHandler<(), impl Middleware<()>> {
pub fn setup_rpc_server(config: &Config, deps: &rpc_apis::ApiDependencies) -> MetaIoHandler<(), impl Middleware<()>> {
let mut handler = MetaIoHandler::with_middleware(LogMiddleware::new());
deps.extend_api(enable_devel_api, &mut handler);
deps.extend_api(config, &mut handler);
rpc_apis::setup_rpc(handler)
}

Expand Down
7 changes: 5 additions & 2 deletions codechain/rpc_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use cnetwork::{EventSender, NetworkControl};
use crpc::{MetaIoHandler, Middleware, Params, Value};
use csync::BlockSyncEvent;

use crate::config::Config;

pub struct ApiDependencies {
pub client: Arc<Client>,
pub miner: Arc<Miner>,
Expand All @@ -31,11 +33,12 @@ pub struct ApiDependencies {
}

impl ApiDependencies {
pub fn extend_api(&self, enable_devel_api: bool, handler: &mut MetaIoHandler<(), impl Middleware<()>>) {
pub fn extend_api(&self, config: &Config, handler: &mut MetaIoHandler<(), impl Middleware<()>>) {
use crpc::v1::*;
handler.extend_with(ChainClient::new(Arc::clone(&self.client)).to_delegate());
handler.extend_with(MempoolClient::new(Arc::clone(&self.client)).to_delegate());
if enable_devel_api {
handler.extend_with(SnapshotClient::new(Arc::clone(&self.client), config.snapshot.path.clone()).to_delegate());
if config.rpc.enable_devel_api {
handler.extend_with(
DevelClient::new(Arc::clone(&self.client), Arc::clone(&self.miner), self.block_sync.clone())
.to_delegate(),
Expand Down
Loading