Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bounded discrete time #4928

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

mversic
Copy link
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
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?


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

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 10716ff to 30eb7a4 Compare August 21, 2024 11:37
@mversic mversic force-pushed the validate_block_time branch 4 times, most recently from 76ba38a to b44bb57 Compare August 22, 2024 15:35
s8sato
s8sato previously approved these changes Aug 23, 2024
Signed-off-by: Marin Veršić <[email protected]>
@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
15 of 18 checks passed
@mversic mversic deleted the validate_block_time branch August 27, 2024 08:48
mversic added a commit that referenced this pull request Aug 30, 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