Skip to content

Commit

Permalink
Do not even propagate future headers (#525)
Browse files Browse the repository at this point in the history
@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.
  • Loading branch information
nfrisby committed Nov 30, 2023
2 parents d5680e7 + 8bb0efc commit 3a1fde0
Show file tree
Hide file tree
Showing 12 changed files with 865 additions and 218 deletions.
@@ -0,0 +1,23 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Patch
- A bullet item for the Patch category.
-->
<!--
### Non-Breaking
- A bullet item for the Non-Breaking category.
-->

### Breaking

- Integrate the new `InFutureCheck` in the ChainSync client, which requires new
fields in `NodeKernalArgs`.
Expand Up @@ -213,7 +213,7 @@ mkHandlers
-- ^ Peer Sharing result computation callback
-> Handlers m addrNTN blk
mkHandlers
NodeKernelArgs {keepAliveRng, miniProtocolParameters}
NodeKernelArgs {chainSyncFutureCheck, keepAliveRng, miniProtocolParameters}
NodeKernel {getChainDB, getMempool, getTopLevelConfig, getTracers = tracers}
computePeers =
Handlers {
Expand All @@ -224,6 +224,7 @@ mkHandlers
(chainSyncPipeliningHighMark miniProtocolParameters))
(contramap (TraceLabelPeer peer) (Node.chainSyncClientTracer tracers))
getTopLevelConfig
chainSyncFutureCheck
(defaultChainDbView getChainDB)
, hChainSyncServer = \peer _version ->
chainSyncHeadersServer
Expand Down
Expand Up @@ -74,6 +74,7 @@ import Ouroboros.Consensus.Fragment.InFuture (CheckInFuture,
ClockSkew)
import qualified Ouroboros.Consensus.Fragment.InFuture as InFuture
import Ouroboros.Consensus.Ledger.Extended (ExtLedgerState (..))
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck as InFutureCheck
import qualified Ouroboros.Consensus.Network.NodeToClient as NTC
import qualified Ouroboros.Consensus.Network.NodeToNode as NTN
import Ouroboros.Consensus.Node.DbLock
Expand Down Expand Up @@ -392,6 +393,7 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
cfg
rnTraceConsensus
btime
(InFutureCheck.realHeaderInFutureCheck llrnMaxClockSkew systemTime)
chainDB
nodeKernel <- initNodeKernel nodeKernelArgs
rnNodeKernelHook registry nodeKernel
Expand Down Expand Up @@ -639,6 +641,7 @@ mkNodeKernelArgs
-> TopLevelConfig blk
-> Tracers m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
-> BlockchainTime m
-> InFutureCheck.HeaderInFutureCheck m blk
-> ChainDB m blk
-> m (NodeKernelArgs m addrNTN (ConnectionId addrNTC) blk)
mkNodeKernelArgs
Expand All @@ -648,6 +651,7 @@ mkNodeKernelArgs
cfg
tracers
btime
chainSyncFutureCheck
chainDB
= do
return NodeKernelArgs
Expand All @@ -657,6 +661,7 @@ mkNodeKernelArgs
, btime
, chainDB
, initChainDB = nodeInitChainDB
, chainSyncFutureCheck
, blockFetchSize = estimateBlockSize
, mempoolCapacityOverride = NoMempoolCapacityBytesOverride
, miniProtocolParameters = defaultMiniProtocolParameters
Expand Down
Expand Up @@ -55,6 +55,8 @@ import Ouroboros.Consensus.Ledger.SupportsPeerSelection
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Mempool
import qualified Ouroboros.Consensus.MiniProtocol.BlockFetch.ClientInterface as BlockFetchClientInterface
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck
(HeaderInFutureCheck)
import Ouroboros.Consensus.Node.Run
import Ouroboros.Consensus.Node.Tracers
import Ouroboros.Consensus.Protocol.Abstract
Expand Down Expand Up @@ -132,6 +134,7 @@ data NodeKernelArgs m addrNTN addrNTC blk = NodeKernelArgs {
, btime :: BlockchainTime m
, chainDB :: ChainDB m blk
, initChainDB :: StorageConfig blk -> InitChainDB m blk -> m ()
, chainSyncFutureCheck :: HeaderInFutureCheck m blk
, blockFetchSize :: Header blk -> SizeInBytes
, mempoolCapacityOverride :: MempoolCapacityBytesOverride
, miniProtocolParameters :: MiniProtocolParameters
Expand Down
Expand Up @@ -70,6 +70,7 @@ import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Mempool
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client as CSClient
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck as InFutureCheck
import qualified Ouroboros.Consensus.Network.NodeToNode as NTN
import Ouroboros.Consensus.Node.ExitPolicy
import Ouroboros.Consensus.Node.InitStorage
Expand Down Expand Up @@ -974,6 +975,10 @@ runThreadNetwork systemTime ThreadNetworkArgs
, btime
, chainDB
, initChainDB = nodeInitChainDB
, chainSyncFutureCheck =
InFutureCheck.realHeaderInFutureCheck
InFuture.defaultClockSkew
(OracularClock.finiteSystemTime clock)
, blockFetchSize = estimateBlockSize
, mempoolCapacityOverride = NoMempoolCapacityBytesOverride
, keepAliveRng = kaRng
Expand Down
@@ -0,0 +1,24 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Patch
- A bullet item for the Patch category.
-->
<!--
### Non-Breaking
- A bullet item for the Non-Breaking category.
-->
### Breaking

- Added a new `InFutureCheck` to the ChainSync client, which requires
additional arguments to the 'chainSyncClient' definition. The node no longer
propagates headers/blocks from the future: a ChainSync client thread now
sleeps until the received header is no longer from the future.
3 changes: 3 additions & 0 deletions ouroboros-consensus/ouroboros-consensus.cabal
Expand Up @@ -141,6 +141,7 @@ library
Ouroboros.Consensus.MiniProtocol.BlockFetch.ClientInterface
Ouroboros.Consensus.MiniProtocol.BlockFetch.Server
Ouroboros.Consensus.MiniProtocol.ChainSync.Client
Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck
Ouroboros.Consensus.MiniProtocol.ChainSync.Server
Ouroboros.Consensus.MiniProtocol.LocalStateQuery.Server
Ouroboros.Consensus.MiniProtocol.LocalTxMonitor.Server
Expand Down Expand Up @@ -483,6 +484,7 @@ test-suite consensus-test
build-depends:
, async
, base
, base-deriving-via
, cardano-binary
, cardano-crypto-class
, cardano-slotting
Expand All @@ -504,6 +506,7 @@ test-suite consensus-test
, ouroboros-network-protocols:{ouroboros-network-protocols, testlib}
, QuickCheck
, quickcheck-state-machine
, quiet
, random
, serialise
, si-timers
Expand Down
Expand Up @@ -16,8 +16,9 @@ module Ouroboros.Consensus.Fragment.InFuture (
-- * Clock skew
, clockSkewInSeconds
, defaultClockSkew
-- ** opaque
-- ** not exporting the constructor
, ClockSkew
, unClockSkew
-- * Testing
, dontCheck
, miracle
Expand Down

0 comments on commit 3a1fde0

Please sign in to comment.