public ReceiptTrie(IReleaseSpec releaseSpec, TxReceipt?[] txReceipts, bool allowProofs = false) : base(allowProofs ? (IDb) new MemDb() : NullDb.Instance, EmptyTreeHash, false, false, NullLogManager.Instance) { _allowProofs = allowProofs; if (txReceipts.Length == 0) { return; } // 3% allocations (2GB) on a Goerli 3M blocks fast sync due to calling receipt encoder hee // avoiding it would require pooling byte arrays and passing them as Spans to temporary trees // a temporary trie would be a trie that exists to create a state root only and then be disposed of for (int i = 0; i < txReceipts.Length; i++) { TxReceipt?currentReceipt = txReceipts[i]; byte[] receiptRlp = Decoder.EncodeNew(currentReceipt, releaseSpec.IsEip658Enabled ? RlpBehaviors.Eip658Receipts : RlpBehaviors.None); if (currentReceipt is not null && currentReceipt.TxType != TxType.Legacy) { receiptRlp = Bytes.Concat((byte)currentReceipt.TxType, receiptRlp); } Set(Rlp.Encode(i).Bytes, receiptRlp); } // additional 3% 2GB is used here for trie nodes creation and root calculation UpdateRootHash(); }
public void Can_do_roundtrip_none_rlp_stream() { TxReceipt txReceipt = Build.A.Receipt.TestObject; txReceipt.Bloom = new Bloom(); txReceipt.Bloom.Set(Keccak.EmptyTreeHash.Bytes); txReceipt.GasUsedTotal = 1000; txReceipt.PostTransactionState = TestItem.KeccakH; ReceiptMessageDecoder decoder = new ReceiptMessageDecoder(); byte[] rlpStreamResult = decoder.EncodeNew(txReceipt, RlpBehaviors.None); TxReceipt deserialized = Rlp.Decode <TxReceipt>(rlpStreamResult, RlpBehaviors.None); AssertMessageReceipt(txReceipt, deserialized); }
public ReceiptTrie(long blockNumber, ISpecProvider specProvider, TxReceipt[] txReceipts, bool allowProofs = false) : base(allowProofs ? (IDb) new MemDb() : NullDb.Instance, EmptyTreeHash, false, false) { _allowProofs = allowProofs; if (txReceipts.Length == 0) { return; } for (int i = 0; i < txReceipts.Length; i++) { byte[] receiptRlp = Decoder.EncodeNew(txReceipts[i], specProvider.GetSpec(blockNumber).IsEip658Enabled ? RlpBehaviors.Eip658Receipts : RlpBehaviors.None); Set(Rlp.Encode(i).Bytes, receiptRlp); } UpdateRootHash(); }
public ReceiptTrie(long blockNumber, ISpecProvider specProvider, TxReceipt[] txReceipts, bool allowProofs = false) : base(allowProofs ? (IDb) new MemDb() : NullDb.Instance, EmptyTreeHash, false, false) { _allowProofs = allowProofs; if (txReceipts.Length == 0) { return; } // 3% allocations (2GB) on a Goerli 3M blocks fast sync due to calling receipt encoder hee // avoiding it would require pooling byte arrays and passing them as Spans to temporary trees // a temporary trie would be a trie that exists to create a state root only and then be disposed of for (int i = 0; i < txReceipts.Length; i++) { byte[] receiptRlp = Decoder.EncodeNew(txReceipts[i], specProvider.GetSpec(blockNumber).IsEip658Enabled ? RlpBehaviors.Eip658Receipts : RlpBehaviors.None); Set(Rlp.Encode(i).Bytes, receiptRlp); } // additional 3% 2GB is used here for trie nodes creation and root calculation UpdateRootHash(); }