From 93418502a48e777b79b474c124ffc434c1054c9a Mon Sep 17 00:00:00 2001 From: siddharth0a Date: Mon, 1 Apr 2024 14:45:41 +0900 Subject: [PATCH] consensus/misc: eip-4844 comment --- consensus/misc/eip4844/eip4844.go | 17 +++++++++++++++++ core/types/block.go | 2 ++ params/protocol_params.go | 23 ++++++++++++++++------- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/consensus/misc/eip4844/eip4844.go b/consensus/misc/eip4844/eip4844.go index 2dad9a0cd3..8fc6f7cb60 100644 --- a/consensus/misc/eip4844/eip4844.go +++ b/consensus/misc/eip4844/eip4844.go @@ -33,8 +33,11 @@ var ( // VerifyEIP4844Header verifies the presence of the excessBlobGas field and that // if the current block contains no transactions, the excessBlobGas is updated // accordingly. +// VerifyEIP4844Header는 excessBlobGas, BlobGasUsed 필드의 존재 등을 검증하고, +// 현재 블록이 트랜잭션을 담고 있지 않으면, 그에따라 excessBlobGas가 업데이트한다. func VerifyEIP4844Header(parent, header *types.Header) error { // Verify the header is not malformed + // 헤더의 형식 검증 if header.ExcessBlobGas == nil { return errors.New("header is missing excessBlobGas") } @@ -42,6 +45,7 @@ func VerifyEIP4844Header(parent, header *types.Header) error { return errors.New("header is missing blobGasUsed") } // Verify that the blob gas used remains within reasonable limits. + // 사용된 blob gas가 합리적인 한도 내에 있는지 검증한다. if *header.BlobGasUsed > params.MaxBlobGasPerBlock { return fmt.Errorf("blob gas used %d exceeds maximum allowance %d", *header.BlobGasUsed, params.MaxBlobGasPerBlock) } @@ -49,6 +53,7 @@ func VerifyEIP4844Header(parent, header *types.Header) error { return fmt.Errorf("blob gas used %d not a multiple of blob gas per blob %d", header.BlobGasUsed, params.BlobTxBlobGasPerBlob) } // Verify the excessBlobGas is correct based on the parent header + // excessBlobGas가 parent header를 기준으로 올바른지 확인한다. var ( parentExcessBlobGas uint64 parentBlobGasUsed uint64 @@ -67,25 +72,32 @@ func VerifyEIP4844Header(parent, header *types.Header) error { // CalcExcessBlobGas calculates the excess blob gas after applying the set of // blobs on top of the excess blob gas. +// CalcExcessBlobGas는 excess blob gas위에 blob set을 적용한 이후, excess blob gas를 계산한다. func CalcExcessBlobGas(parentExcessBlobGas uint64, parentBlobGasUsed uint64) uint64 { excessBlobGas := parentExcessBlobGas + parentBlobGasUsed + // 목표치 이하로 사용했으므로 excess blob gas = 0 if excessBlobGas < params.BlobTxTargetBlobGasPerBlock { return 0 } + // excessBlobGas = (parentExcessBlobGas + parentBlobGasUsed) - BlobTxTargetBlobGasPerBlock return excessBlobGas - params.BlobTxTargetBlobGasPerBlock } // CalcBlobFee calculates the blobfee from the header's excess blob gas field. +// CalcBlobFee는 header의 excess blob gase field로 blobfee를 계산한다. func CalcBlobFee(excessBlobGas uint64) *big.Int { return fakeExponential(minBlobGasPrice, new(big.Int).SetUint64(excessBlobGas), blobGaspriceUpdateFraction) } // fakeExponential approximates factor * e ** (numerator / denominator) using // Taylor expansion. +// 테일러 급수 전개로 근사적으로 계산 +// e^x = 1 + x + x^2/2! + x^3/3! + ... func fakeExponential(factor, numerator, denominator *big.Int) *big.Int { var ( output = new(big.Int) accum = new(big.Int).Mul(factor, denominator) + // ------ accoum = new(big.Int).Set(factor) ) for i := 1; accum.Sign() > 0; i++ { output.Add(output, accum) @@ -95,4 +107,9 @@ func fakeExponential(factor, numerator, denominator *big.Int) *big.Int { accum.Div(accum, big.NewInt(int64(i))) } return output.Div(output, denominator) + // ------ return output + // 왜 굳이 마지막에 output을 denominator로 나누는거지? + // 내 생각엔 함수의 시작에서 accum을 정의할때 factor와 denominator의 곱을 저장하기 때문에 + // denominator로 나누어준 거 같은데 그냥 처음부터 accum을 factor로 정의해서 + // denominator를 곱하고 나누는 연산과정을 생략할 수 있지 않나? } diff --git a/core/types/block.go b/core/types/block.go index 1a357baa3a..14c1bea48c 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -86,9 +86,11 @@ type Header struct { WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` // BlobGasUsed was added by EIP-4844 and is ignored in legacy headers. + // BlobGasUsed는 EIP-4844에 추가되고, legacy headers에서는 무시된다. BlobGasUsed *uint64 `json:"blobGasUsed" rlp:"optional"` // ExcessBlobGas was added by EIP-4844 and is ignored in legacy headers. + // ExcessBlobGas는 EIP-4844에 추가되고, legacy headers에서는 무시된다. ExcessBlobGas *uint64 `json:"excessBlobGas" rlp:"optional"` // ParentBeaconRoot was added by EIP-4788 and is ignored in legacy headers. diff --git a/params/protocol_params.go b/params/protocol_params.go index d45af37433..32ce83f255 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -166,15 +166,24 @@ const ( RefundQuotient uint64 = 2 RefundQuotientEIP3529 uint64 = 5 - BlobTxBytesPerFieldElement = 32 // Size in bytes of a field element - BlobTxFieldElementsPerBlob = 4096 // Number of field elements stored in a single data blob - BlobTxBlobGasPerBlob = 1 << 17 // Gas consumption of a single data blob (== blob byte size) - BlobTxMinBlobGasprice = 1 // Minimum gas price for data blobs - BlobTxBlobGaspriceUpdateFraction = 3338477 // Controls the maximum rate of change for blob gas price - BlobTxPointEvaluationPrecompileGas = 50000 // Gas price for the point evaluation precompile. + BlobTxBytesPerFieldElement = 32 // Size in bytes of a field element + BlobTxFieldElementsPerBlob = 4096 // Number of field elements stored in a single data blob + BlobTxBlobGasPerBlob = 1 << 17 // Gas consumption of a single data blob (== blob byte size) + // 한 data blob당 가스 소모량(blob의 byte size) + + BlobTxMinBlobGasprice = 1 // Minimum gas price for data blobs + // data blobs의 최소 gas price + + BlobTxBlobGaspriceUpdateFraction = 3338477 // Controls the maximum rate of change for blob gas price + // blob gas price의 최대 변동 폭 제어 + + BlobTxPointEvaluationPrecompileGas = 50000 // Gas price for the point evaluation precompile. BlobTxTargetBlobGasPerBlock = 3 * BlobTxBlobGasPerBlob // Target consumable blob gas for data blobs per block (for 1559-like pricing) - MaxBlobGasPerBlock = 6 * BlobTxBlobGasPerBlob // Maximum consumable blob gas for data blobs per block + // 블록당 data blobs에 소비될 수 있는 목표 blob gas + + MaxBlobGasPerBlock = 6 * BlobTxBlobGasPerBlob // Maximum consumable blob gas for data blobs per block + // 블록당 data blobs에 소비될 수 있는 최대 blob gas ) // Gas discount table for BLS12-381 G1 and G2 multi exponentiation operations