Skip to content

Commit 3a1fde0

Browse files
authored
Do not even propagate future headers (#525)
@njd42 and I came up with this idea a couple weeks ago, during a chat about the vagaries of NTP/clocks/etc. See the commit message of the 'consensus: do not even propagate future headers' commit. The main concrete benefits: - It's a step towards Chronos and that helps simplify/ground our story around future blocks. - A network-load optimization of sorts: if someone with a horribly out of sync clock sends a block 60 seconds early, the direct neighbors won't even propagate it.
2 parents d5680e7 + 8bb0efc commit 3a1fde0

File tree

12 files changed

+865
-218
lines changed

12 files changed

+865
-218
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Patch
9+
10+
- A bullet item for the Patch category.
11+
12+
-->
13+
<!--
14+
### Non-Breaking
15+
16+
- A bullet item for the Non-Breaking category.
17+
18+
-->
19+
20+
### Breaking
21+
22+
- Integrate the new `InFutureCheck` in the ChainSync client, which requires new
23+
fields in `NodeKernalArgs`.

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Network/NodeToNode.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ mkHandlers
213213
-- ^ Peer Sharing result computation callback
214214
-> Handlers m addrNTN blk
215215
mkHandlers
216-
NodeKernelArgs {keepAliveRng, miniProtocolParameters}
216+
NodeKernelArgs {chainSyncFutureCheck, keepAliveRng, miniProtocolParameters}
217217
NodeKernel {getChainDB, getMempool, getTopLevelConfig, getTracers = tracers}
218218
computePeers =
219219
Handlers {
@@ -224,6 +224,7 @@ mkHandlers
224224
(chainSyncPipeliningHighMark miniProtocolParameters))
225225
(contramap (TraceLabelPeer peer) (Node.chainSyncClientTracer tracers))
226226
getTopLevelConfig
227+
chainSyncFutureCheck
227228
(defaultChainDbView getChainDB)
228229
, hChainSyncServer = \peer _version ->
229230
chainSyncHeadersServer

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import Ouroboros.Consensus.Fragment.InFuture (CheckInFuture,
7474
ClockSkew)
7575
import qualified Ouroboros.Consensus.Fragment.InFuture as InFuture
7676
import Ouroboros.Consensus.Ledger.Extended (ExtLedgerState (..))
77+
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck as InFutureCheck
7778
import qualified Ouroboros.Consensus.Network.NodeToClient as NTC
7879
import qualified Ouroboros.Consensus.Network.NodeToNode as NTN
7980
import Ouroboros.Consensus.Node.DbLock
@@ -392,6 +393,7 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
392393
cfg
393394
rnTraceConsensus
394395
btime
396+
(InFutureCheck.realHeaderInFutureCheck llrnMaxClockSkew systemTime)
395397
chainDB
396398
nodeKernel <- initNodeKernel nodeKernelArgs
397399
rnNodeKernelHook registry nodeKernel
@@ -639,6 +641,7 @@ mkNodeKernelArgs
639641
-> TopLevelConfig blk
640642
-> Tracers m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
641643
-> BlockchainTime m
644+
-> InFutureCheck.HeaderInFutureCheck m blk
642645
-> ChainDB m blk
643646
-> m (NodeKernelArgs m addrNTN (ConnectionId addrNTC) blk)
644647
mkNodeKernelArgs
@@ -648,6 +651,7 @@ mkNodeKernelArgs
648651
cfg
649652
tracers
650653
btime
654+
chainSyncFutureCheck
651655
chainDB
652656
= do
653657
return NodeKernelArgs
@@ -657,6 +661,7 @@ mkNodeKernelArgs
657661
, btime
658662
, chainDB
659663
, initChainDB = nodeInitChainDB
664+
, chainSyncFutureCheck
660665
, blockFetchSize = estimateBlockSize
661666
, mempoolCapacityOverride = NoMempoolCapacityBytesOverride
662667
, miniProtocolParameters = defaultMiniProtocolParameters

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/NodeKernel.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ import Ouroboros.Consensus.Ledger.SupportsPeerSelection
5555
import Ouroboros.Consensus.Ledger.SupportsProtocol
5656
import Ouroboros.Consensus.Mempool
5757
import qualified Ouroboros.Consensus.MiniProtocol.BlockFetch.ClientInterface as BlockFetchClientInterface
58+
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck
59+
(HeaderInFutureCheck)
5860
import Ouroboros.Consensus.Node.Run
5961
import Ouroboros.Consensus.Node.Tracers
6062
import Ouroboros.Consensus.Protocol.Abstract
@@ -132,6 +134,7 @@ data NodeKernelArgs m addrNTN addrNTC blk = NodeKernelArgs {
132134
, btime :: BlockchainTime m
133135
, chainDB :: ChainDB m blk
134136
, initChainDB :: StorageConfig blk -> InitChainDB m blk -> m ()
137+
, chainSyncFutureCheck :: HeaderInFutureCheck m blk
135138
, blockFetchSize :: Header blk -> SizeInBytes
136139
, mempoolCapacityOverride :: MempoolCapacityBytesOverride
137140
, miniProtocolParameters :: MiniProtocolParameters

ouroboros-consensus-diffusion/src/unstable-diffusion-testlib/Test/ThreadNet/Network.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import Ouroboros.Consensus.Ledger.SupportsMempool
7070
import Ouroboros.Consensus.Ledger.SupportsProtocol
7171
import Ouroboros.Consensus.Mempool
7272
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client as CSClient
73+
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck as InFutureCheck
7374
import qualified Ouroboros.Consensus.Network.NodeToNode as NTN
7475
import Ouroboros.Consensus.Node.ExitPolicy
7576
import Ouroboros.Consensus.Node.InitStorage
@@ -974,6 +975,10 @@ runThreadNetwork systemTime ThreadNetworkArgs
974975
, btime
975976
, chainDB
976977
, initChainDB = nodeInitChainDB
978+
, chainSyncFutureCheck =
979+
InFutureCheck.realHeaderInFutureCheck
980+
InFuture.defaultClockSkew
981+
(OracularClock.finiteSystemTime clock)
977982
, blockFetchSize = estimateBlockSize
978983
, mempoolCapacityOverride = NoMempoolCapacityBytesOverride
979984
, keepAliveRng = kaRng
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Patch
9+
10+
- A bullet item for the Patch category.
11+
12+
-->
13+
<!--
14+
### Non-Breaking
15+
16+
- A bullet item for the Non-Breaking category.
17+
18+
-->
19+
### Breaking
20+
21+
- Added a new `InFutureCheck` to the ChainSync client, which requires
22+
additional arguments to the 'chainSyncClient' definition. The node no longer
23+
propagates headers/blocks from the future: a ChainSync client thread now
24+
sleeps until the received header is no longer from the future.

ouroboros-consensus/ouroboros-consensus.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ library
141141
Ouroboros.Consensus.MiniProtocol.BlockFetch.ClientInterface
142142
Ouroboros.Consensus.MiniProtocol.BlockFetch.Server
143143
Ouroboros.Consensus.MiniProtocol.ChainSync.Client
144+
Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck
144145
Ouroboros.Consensus.MiniProtocol.ChainSync.Server
145146
Ouroboros.Consensus.MiniProtocol.LocalStateQuery.Server
146147
Ouroboros.Consensus.MiniProtocol.LocalTxMonitor.Server
@@ -483,6 +484,7 @@ test-suite consensus-test
483484
build-depends:
484485
, async
485486
, base
487+
, base-deriving-via
486488
, cardano-binary
487489
, cardano-crypto-class
488490
, cardano-slotting
@@ -504,6 +506,7 @@ test-suite consensus-test
504506
, ouroboros-network-protocols:{ouroboros-network-protocols, testlib}
505507
, QuickCheck
506508
, quickcheck-state-machine
509+
, quiet
507510
, random
508511
, serialise
509512
, si-timers

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Fragment/InFuture.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ module Ouroboros.Consensus.Fragment.InFuture (
1616
-- * Clock skew
1717
, clockSkewInSeconds
1818
, defaultClockSkew
19-
-- ** opaque
19+
-- ** not exporting the constructor
2020
, ClockSkew
21+
, unClockSkew
2122
-- * Testing
2223
, dontCheck
2324
, miracle

0 commit comments

Comments
 (0)