Skip to content

Commit

Permalink
Upper bound for CBOR-in-CBOR tag is 7 instead of 5 bytes
Browse files Browse the repository at this point in the history
Apparently we sometimes generate blocks that are 65536 bytes large or more,
requiring a 7 byte CBOR-in-CBOR tag (65535 would only require 5 bytes), failing
the test added in #2481, as our upper bound assumed 5 bytes.
  • Loading branch information
mrBliss authored and nc6 committed Aug 3, 2020
1 parent 4f054dc commit 9f7ab0a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
Expand Up @@ -153,7 +153,14 @@ instance GetHeader ByronBlock where
CC.ABOBBoundary blk -> recoverBytes blk
}
where
overhead = 5 {- CBOR-in-CBOR -} + 2 {- EBB tag -}
-- The maximum block size is 65536, the CBOR-in-CBOR tag for this block
-- is:
--
-- > D8 18 # tag(24)
-- > 1A 00010000 # bytes(65536)
--
-- Which is 7 bytes, enough for up to 4294967295 bytes.
overhead = 7 {- CBOR-in-CBOR -} + 2 {- EBB tag -}

-- Check if a block matches its header
--
Expand Down
Binary file not shown.
Binary file not shown.
Expand Up @@ -374,7 +374,14 @@ instance ConfigSupportsNode (ShelleyBlock c) where
instance TPraosCrypto c => RunNode (ShelleyBlock c) where
nodeBlockFetchSize hdr = overhead + headerSize + bodySize
where
overhead = 5 {- CBOR-in-CBOR -} + 1 {- encodeListLen -}
-- The maximum block size is 65536, the CBOR-in-CBOR tag for this block
-- is:
--
-- > D8 18 # tag(24)
-- > 1A 00010000 # bytes(65536)
--
-- Which is 7 bytes, enough for up to 4294967295 bytes.
overhead = 7 {- CBOR-in-CBOR -} + 1 {- encodeListLen -}
bodySize = fromIntegral . SL.bsize . SL.bhbody . shelleyHeaderRaw $ hdr
headerSize = fromIntegral . SL.bHeaderSize . shelleyHeaderRaw $ hdr

Expand Down
Expand Up @@ -58,7 +58,7 @@ instance ( LedgerSupportsProtocol (SimpleBlock SimpleMockCrypto ext)
, RunMockBlock SimpleMockCrypto ext
) => RunNode (SimpleBlock SimpleMockCrypto ext) where
nodeBlockFetchSize hdr =
5 {- CBOR-in-CBOR -} + 1 {- encodeListLen 2 -} + hdrSize + bodySize
7 {- CBOR-in-CBOR -} + 1 {- encodeListLen 2 -} + hdrSize + bodySize
where
hdrSize = fromIntegral (Lazy.length (serialise hdr))
bodySize = simpleBodySize (simpleHeaderStd hdr)
Expand Down

0 comments on commit 9f7ab0a

Please sign in to comment.