Skip to content

Commit edec28f

Browse files
authored
Merge pull request #332 from DMDcoin/4.0
4.0.2 release
2 parents 0838d7e + 5e6de72 commit edec28f

File tree

19 files changed

+220
-69
lines changed

19 files changed

+220
-69
lines changed

CHANGELOG.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
## Diamond Node Software 4.0.2
2+
3+
4+
### New behavior for validator nodes
5+
- [Autoshutdown if a Node becomes a regular Node](https://github.com/DMDcoin/diamond-node/issues/322)
6+
- [Remove empty blocks during key gen phases behaviour](https://github.com/DMDcoin/diamond-node/issues/327)
7+
- [Service Transaction cleanup (garbage collect)](https://github.com/DMDcoin/diamond-node/issues/172)
8+
9+
### RPC
10+
- [Gas price from contracts](https://github.com/DMDcoin/diamond-node/issues/159)
11+
12+
### Further improvements
13+
- [FIXED: received transactions are getting pooled, if announced by another peer](https://github.com/DMDcoin/diamond-node/issues/304)
14+
- [FIXED: dropped transactions are getting pooled](https://github.com/DMDcoin/diamond-node/issues/303)
15+
- [FIXED: key generation can panic if faulty validators write malicious parts](https://github.com/DMDcoin/diamond-node/issues/100)
16+
- [FIXED: already included transactions are refretched from peers](https://github.com/DMDcoin/diamond-node/issues/196)
17+
- [FIXED:not staked nodes write log entries about service transactions](https://github.com/DMDcoin/diamond-node/issues/323)
18+
- [Gracefull Node Shutdown: increase to 15 seconds](https://github.com/DMDcoin/diamond-node/issues/321)
19+
20+
121
## Diamond Node Software 4.0.1
222

3-
First hotfix
23+
OPTIONAL: First hotfix
424
Mitigates the transaction spam caused by flaws in the transaction management of report disconnectivity transactions.
525

626
- [Reduce Intervals for connectivity checks](https://github.com/DMDcoin/diamond-node/issues/313)

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description = "Diamond Node"
33
name = "diamond-node"
44
# NOTE Make sure to update util/version/Cargo.toml as well
5-
version = "4.0.1"
5+
version = "4.0.2"
66
license = "GPL-3.0"
77
authors = [
88
"bit.diamonds developers",

bin/oe/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ impl RunningClient {
723723
.name("diamond-node-force-quit".to_string())
724724
.spawn(move || {
725725

726-
let duration_soft = 5;
726+
let duration_soft = 15;
727727
// we make a force quit if after 90 seconds, if this shutdown routine
728728
std::thread::sleep(Duration::from_secs(duration_soft));
729729
warn!(target: "shutdown", "shutdown not happened within {duration_soft} seconds, starting force exiting the process.");

crates/concensus/miner/src/pool/queue.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ use crate::pool::{
4141
verifier, PendingOrdering, PendingSettings, PrioritizationStrategy,
4242
};
4343

44+
use super::VerifiedTransaction;
45+
4446
type Listener = (
4547
LocalTransactionsList,
4648
(listener::Notifier, listener::Logger),
@@ -413,6 +415,17 @@ impl TransactionQueue {
413415
.collect()
414416
}
415417

418+
/// Performs garbage collection on the pool of this `TransactionQueue` for free service transactions.
419+
/// Removes transactions that are not valid anymore.
420+
/// The process executes listener calls.
421+
pub fn garbage_collect<F: Fn(&VerifiedTransaction) -> bool>(
422+
&self,
423+
service_transaction_check: F,
424+
) {
425+
let mut pool = self.pool.write();
426+
pool.garbage_collect(service_transaction_check);
427+
}
428+
416429
/// Computes unordered set of pending hashes.
417430
///
418431
/// Since strict nonce-checking is not required, you may get some false positive future transactions as well.

crates/ethcore/service/src/service.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
233233
ClientIoMessage::Execute(ref exec) => {
234234
(*exec.0)(&self.client);
235235
}
236-
_ => {} // ignore other messages
236+
ClientIoMessage::NewChainHead => {
237+
self.client.garbage_collect_in_queue();
238+
}
237239
}
238240
}
239241
}

crates/ethcore/src/client/client.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ pub struct Client {
306306

307307
shutdown: Arc<ShutdownManager>,
308308

309+
/// block number and block hash of latest gc.
310+
/// this information is used to avoid double garbage collection.
311+
garbage_collect_latest_block: Mutex<(u64, H256)>,
312+
309313
statistics: ClientStatistics,
310314
}
311315

@@ -842,6 +846,8 @@ impl Importer {
842846
warn!("Failed to prune ancient state data: {}", e);
843847
}
844848

849+
client.schedule_garbage_collect_in_queue();
850+
845851
route
846852
}
847853

@@ -1107,6 +1113,7 @@ impl Client {
11071113
importer,
11081114
config,
11091115
shutdown,
1116+
garbage_collect_latest_block: Mutex::new((0, H256::zero())),
11101117
statistics,
11111118
});
11121119

@@ -1540,6 +1547,52 @@ impl Client {
15401547
}
15411548
}
15421549

1550+
/// Schedule garbage collection of invalid service transactions from the transaction queue based on the given block hash.
1551+
pub fn schedule_garbage_collect_in_queue(&self) {
1552+
let m = ClientIoMessage::execute(|c| c.garbage_collect_in_queue());
1553+
if let Err(e) = self.io_channel.read().send(m) {
1554+
error!(target: "client", "Failed to schedule garbage collection in transaction queue for block {:?}", e);
1555+
}
1556+
}
1557+
1558+
/// Garbage collect invalid service transactions from the transaction queue based on the given block header.
1559+
pub fn garbage_collect_in_queue(&self) {
1560+
let machine = self.engine().machine();
1561+
1562+
match &self.block_header_decoded(BlockId::Latest) {
1563+
Some(block_header) => {
1564+
{
1565+
// scope for mutex.
1566+
let mut last_gc = self.garbage_collect_latest_block.lock();
1567+
1568+
if block_header.number() == last_gc.0 && block_header.hash() == last_gc.1 {
1569+
// already gced for this block, or gc is ongoing.
1570+
// we can return here.
1571+
return;
1572+
}
1573+
1574+
// we treat ongoing gc as DONE, to avoid blocking of the message channel
1575+
last_gc.0 = block_header.number();
1576+
last_gc.1 = block_header.hash();
1577+
}
1578+
1579+
// here hides an accepted race condition.
1580+
// latest block could change during long ongoing GCs.
1581+
// this could be avoided developing a more complex GC logic.
1582+
// but the GC blocks the tx queue, so it has to be blazing fast.
1583+
self.importer.miner.collect_garbage(|tx|
1584+
match machine.verify_transaction(tx.signed(), block_header, self) {
1585+
Ok(_) => true,
1586+
Err(e) => {
1587+
trace!(target: "client", "collected garbage transaction from {:?}: {:?} reason: {:?}", tx.signed().sender(), tx.signed().hash, e);
1588+
false
1589+
},
1590+
});
1591+
}
1592+
None => {}
1593+
}
1594+
}
1595+
15431596
fn check_garbage(&self) {
15441597
self.chain.read().collect_garbage();
15451598
self.importer.block_queue.collect_garbage();

crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,25 @@ pub fn acks_of_address(
156156
if serialized_ack.is_empty() {
157157
return Err(CallError::ReturnValueInvalid);
158158
}
159-
let deserialized_ack: Ack = bincode::deserialize(&serialized_ack).unwrap();
160-
let outcome = skg
161-
.handle_ack(vmap.get(&address).unwrap(), deserialized_ack)
162-
.unwrap();
159+
let deserialized_ack: Ack = match bincode::deserialize(&serialized_ack) {
160+
Ok(ack) => ack,
161+
Err(e) => {
162+
error!(target: "engine", "Failed to deserialize Ack #{} for address {}: {:?}", n, address, e);
163+
return Err(CallError::ReturnValueInvalid);
164+
}
165+
};
166+
167+
let outcome = match skg.handle_ack(vmap.get(&address).unwrap(), deserialized_ack) {
168+
Ok(s) => s,
169+
Err(e) => {
170+
error!(target: "engine", "Failed to handle Ack #{} for address {}: {:?}", n, address, e);
171+
return Err(CallError::ReturnValueInvalid);
172+
}
173+
};
174+
163175
if let AckOutcome::Invalid(fault) = outcome {
164-
panic!("Expected Ack Outcome to be valid. {:?}", fault);
176+
error!(target: "engine", "Invalid Ack Outcome for #{} for address {}: {:?}", n, address, fault);
177+
return Err(CallError::ReturnValueInvalid);
165178
}
166179
}
167180

crates/ethcore/src/engines/hbbft/contracts/staking.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ pub fn get_posdao_epoch_start(
3535
call_const_staking!(c, staking_epoch_start_block)
3636
}
3737

38-
pub fn start_time_of_next_phase_transition(client: &dyn EngineClient) -> Result<U256, CallError> {
39-
let c = BoundContract::bind(client, BlockId::Latest, *STAKING_CONTRACT_ADDRESS);
40-
call_const_staking!(c, start_time_of_next_phase_transition)
41-
}
42-
4338
pub fn candidate_min_stake(client: &dyn EngineClient) -> Result<U256, CallError> {
4439
let c = BoundContract::bind(client, BlockId::Latest, *STAKING_CONTRACT_ADDRESS);
4540
call_const_staking!(c, candidate_min_stake)

crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl HbbftEarlyEpochEndManager {
112112
signing_address: signing_address.clone(),
113113
};
114114

115-
info!(target: "engine", "early-epoch-end: HbbftEarlyEpochEndManager created. start_time {now:?}, start_block: {epoch_start_block}");
115+
trace!(target: "engine", "early-epoch-end: HbbftEarlyEpochEndManager created. start_time {now:?}, start_block: {epoch_start_block}");
116116

117117
return Some(result);
118118
}

0 commit comments

Comments
 (0)