Skip to content

feat: bounded discrete time#4928

Merged
nxsaken merged 1 commit intohyperledger-iroha:mainfrom
mversic:validate_block_time
Aug 27, 2024
Merged

feat: bounded discrete time#4928
nxsaken merged 1 commit intohyperledger-iroha:mainfrom
mversic:validate_block_time

Conversation

@mversic
Copy link
Copy Markdown
Contributor

@mversic mversic commented Aug 2, 2024

Description

  • put a lower bound on block time (previous block time)
  • put upper bound on the block time (less than peer current time)

Linked issue

Closes #4962

Benefits

now have a bounded concept of time that is synchronized across peers.
the time is discrete with increment intervals being the time between 2 blocks

Checklist

  • I've read CONTRIBUTING.md
  • I've used the standard signed-off commit format (or will squash just before merging)
  • All applicable CI checks pass (or I promised to make them pass later)
  • (optional) I've written unit tests for the code changes
  • I replied to all comments after code review, marking all implemented changes with thumbs up

@mversic mversic force-pushed the validate_block_time branch 2 times, most recently from 2d21f6c to f45e0d4 Compare August 2, 2024 01:31
@mversic mversic changed the title feature: synchronized bounded time feature: synchronized bounded discrete time Aug 2, 2024
Copy link
Copy Markdown
Contributor

@Erigara Erigara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide more context for this change.

Also i can't see synchronization part of this PR, am i missing something?

Comment thread data_model/src/block.rs Outdated
Comment thread core/src/block.rs Outdated
Comment thread data_model/src/block.rs Outdated

fn validate(self) -> Result<BlockHeader, &'static str> {
#[cfg(feature = "std")]
if std::time::Instant::now().elapsed() < self.creation_time() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit concerned that block validity now depends on when block was received.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain why do you think this is an issue?

Copy link
Copy Markdown
Contributor

@Erigara Erigara Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think it compromise security, but might harm liveliness if peers clocks drift from each other

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, drift can happen. This PR assumed nodes synchronize time with an external authority often enough. We can trust that OS will do it (through std::time::SystemTime and ntpd on linux) or we can introduce a separate time tracking via NTP as part of the iroha code running on the node

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is upper bound. What do you think about having the lower bound? I can only define lower bound if I define both lower and upper. Because if lower bound is defined and block time is set far into the future no new blocks can be produced

@mversic mversic force-pushed the validate_block_time branch from f45e0d4 to 5b31646 Compare August 2, 2024 09:16
@github-actions github-actions bot added the api-changes Changes in the API for client libraries label Aug 2, 2024
@mversic mversic changed the title feature: synchronized bounded discrete time feature: bounded discrete time Aug 2, 2024
@mversic mversic force-pushed the validate_block_time branch 5 times, most recently from c48948d to 36dd3f9 Compare August 2, 2024 09:22
@mversic mversic changed the title feature: bounded discrete time feat: bounded discrete time Aug 2, 2024
@mversic
Copy link
Copy Markdown
Contributor Author

mversic commented Aug 2, 2024

Can you provide more context for this change.

Sequence of blocks is now guaranteed to have monotonically increasing time. The leader can't just completely fabricate the voted block's creation time because the creation time has to be within some limits (after previous block creation time, but before current validator/observer/proxy node time). If the leader tells a lie within the imposed limits, given enough rotations we should again arrive to the correct value of the time. On average, I'd say that time should remain quite close to the current time (a little bit behind, never in the future).

Also i can't see synchronization part of this PR, am i missing something?

I removed that word. I meant that it's synchronized in the sense that everybody can agree when the block was created (within an interval). Peers can use blocks creation time to reason about current time. Whatever is the last creation time is the current time across all peers and it increases discretely in intervals.

Example

  1. A block was created at 11:25AM and committed
  2. 11:25AM becomes the current time (the network is certain that the actual time is no less than that)
  3. Block was committed at 11:35
  4. 11:35AM becomes the current time (the network is certain that the actual time is no less than that)

time is discrete in the blockchain because 11:30 is not a valid time, only 11:25, 11:35, etc are valid timestamps

Implementing time based logic in a smart contract

A smart contract can be given latest block creation time as the current time (a sort of synchronization point) and have logic based on that (understanding the limitations). In the previous example, if the smart contract was written so that it performs a certain action if time is past 11:30AM, it will do it at 11:35AM. But the time of the execution is guaranteed to never be less than 11:30AM

@Erigara
Copy link
Copy Markdown
Contributor

Erigara commented Aug 2, 2024

To avoid block rejection can't leader select block time to be as close to the previous block time as possible?
I think it would be considered valid because it's in the range (previous_block_time, min(voting_peer_current_time_1, voting_peer_current_time_n)].

@mversic
Copy link
Copy Markdown
Contributor Author

mversic commented Aug 2, 2024

To avoid block rejection can't leader select block time to be as close to the previous block time as possible? I think it would be considered valid because it's in the range (previous_block_time, min(voting_peer_current_time_1, voting_peer_current_time_n)].

yes, but then the next leader will correct it, or the one after that. The error doesn't compound or get propagated indefinitely. Network time can drift from the actual current time but not too far.

@mversic mversic force-pushed the validate_block_time branch from 36dd3f9 to 82d058c Compare August 2, 2024 10:40
@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 2, 2024

@BAStos525

@github-actions github-actions bot added the config-changes Changes in configuration and start up of the Iroha label Aug 2, 2024
@mversic mversic force-pushed the validate_block_time branch 4 times, most recently from 1f2d4c0 to 8e70e81 Compare August 2, 2024 13:18
@mversic mversic force-pushed the validate_block_time branch 2 times, most recently from 0b3a15c to 5331ccd Compare August 15, 2024 09:58
@mversic mversic force-pushed the validate_block_time branch 2 times, most recently from 10716ff to 30eb7a4 Compare August 21, 2024 11:37
Comment thread core/benches/kura.rs
Comment thread data_model/src/block.rs
@mversic mversic force-pushed the validate_block_time branch 4 times, most recently from 76ba38a to b44bb57 Compare August 22, 2024 15:35
Comment thread core/src/queue.rs Outdated
Comment thread torii/src/routing.rs
s8sato
s8sato previously approved these changes Aug 23, 2024
Comment thread core/src/block.rs Outdated
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
@nxsaken nxsaken force-pushed the validate_block_time branch from 561aa21 to 54f4aed Compare August 27, 2024 08:10
@nxsaken nxsaken disabled auto-merge August 27, 2024 08:10
@nxsaken nxsaken merged commit 3e9cc6f into hyperledger-iroha:main Aug 27, 2024
@DCNick3 DCNick3 mentioned this pull request Sep 3, 2024
2 tasks
@dima74 dima74 mentioned this pull request Sep 24, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-changes Changes in the API for client libraries config-changes Changes in configuration and start up of the Iroha

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bounded time

6 participants