From f78f20c2bd77b7aa9b36243069e2e6f125638218 Mon Sep 17 00:00:00 2001 From: kdeme Date: Thu, 8 Feb 2024 13:16:00 +0100 Subject: [PATCH] Remove duplicated e2store code --- fluffy/eth_data/era1.nim | 77 +++--------------------- fluffy/eth_data/history_data_ssz_e2s.nim | 6 +- vendor/nimbus-eth2 | 2 +- 3 files changed, 10 insertions(+), 75 deletions(-) diff --git a/fluffy/eth_data/era1.nim b/fluffy/eth_data/era1.nim index febf184ea8..693636aea2 100644 --- a/fluffy/eth_data/era1.nim +++ b/fluffy/eth_data/era1.nim @@ -61,72 +61,6 @@ type startNumber*: uint64 offsets*: seq[int64] # Absolute positions in file -template lenu64(x: untyped): untyped = - uint64(len(x)) - -## Following procs are more e2s specific and copied from e2store.nim -## TODO: Split up e2store.nim between e2s and era1 specific parts and reuse -## e2s code. - -proc toString(v: IoErrorCode): string = - try: ioErrorMsg(v) - except Exception as e: raiseAssert e.msg - -proc append(f: IoHandle, data: openArray[byte]): Result[void, string] = - if (? writeFile(f, data).mapErr(toString)) != data.len.uint: - return err("could not write data") - ok() - -proc appendHeader(f: IoHandle, typ: Type, dataLen: int): Result[int64, string] = - if dataLen.uint64 > uint32.high: - return err("entry does not fit 32-bit length") - - let start = ? getFilePos(f).mapErr(toString) - - ? append(f, typ) - ? append(f, toBytesLE(dataLen.uint32)) - ? append(f, [0'u8, 0'u8]) - - ok(start) - -proc checkBytesLeft(f: IoHandle, expected: int64): Result[void, string] = - let size = ? getFileSize(f).mapErr(toString) - if expected > size: - return err("Record extends past end of file") - - let pos = ? getFilePos(f).mapErr(toString) - if expected > size - pos: - return err("Record extends past end of file") - - ok() - -proc readFileExact(f: IoHandle, buf: var openArray[byte]): Result[void, string] = - if (? f.readFile(buf).mapErr(toString)) != buf.len().uint: - return err("missing data") - ok() - -proc readHeader(f: IoHandle): Result[Header, string] = - var buf: array[10, byte] - ? readFileExact(f, buf.toOpenArray(0, 7)) - - var - typ: Type - discard typ.copyFrom(buf) - - # Conversion safe because we had only 4 bytes of length data - let len = (uint32.fromBytesLE(buf.toOpenArray(2, 5))).int64 - - # No point reading these.. - if len > int.high(): return err("header length exceeds int.high") - - # Must have at least that much data, or header is invalid - ? f.checkBytesLeft(len) - - ok(Header(typ: typ, len: int(len))) - -## Following types & procs are era1 specific - -type Era1* = distinct uint64 # Period of 8192 blocks (not an exact time unit) Era1Group* = object @@ -135,9 +69,14 @@ type # As stated, not really a time unit but nevertheless, need the borrows ethTimeUnit Era1 -# Note: appendIndex, appendRecord and readIndex for BlockIndex are only -# different from its consensus layer counter parts because of usage of slot vs -# blockNumber. In practise, they do the same thing. +template lenu64(x: untyped): untyped = + uint64(len(x)) + +# Note: appendIndex, appendRecord and readIndex for BlockIndex are very similar +# to its consensus layer counter parts. The difference lies in the naming of +# slots vs block numbers and there is different behavior for the first era +# (first slot) and the last era (era1 ends at merge block). + proc appendIndex*( f: IoHandle, startNumber: uint64, offsets: openArray[int64]): Result[int64, string] = diff --git a/fluffy/eth_data/history_data_ssz_e2s.nim b/fluffy/eth_data/history_data_ssz_e2s.nim index a6d0430685..1a34babd60 100644 --- a/fluffy/eth_data/history_data_ssz_e2s.nim +++ b/fluffy/eth_data/history_data_ssz_e2s.nim @@ -1,5 +1,5 @@ # Nimbus - Portal Network -# Copyright (c) 2022-2023 Status Research & Development GmbH +# Copyright (c) 2022-2024 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -15,10 +15,6 @@ import export results -proc toString*(v: IoErrorCode): string = - try: ioErrorMsg(v) - except Exception as e: raiseAssert e.msg - # Reading SSZ data from files proc readAccumulator*(file: string): Result[FinishedAccumulator, string] = diff --git a/vendor/nimbus-eth2 b/vendor/nimbus-eth2 index e398078abc..3c0fee6b2f 160000 --- a/vendor/nimbus-eth2 +++ b/vendor/nimbus-eth2 @@ -1 +1 @@ -Subproject commit e398078abcfb81dbce1804fa9920d2e92e493c64 +Subproject commit 3c0fee6b2fe4fbb1e16bd01bc9d4898dd0d864a1