Skip to content

Commit b43f139

Browse files
committed
fix converting baseFeePerGas
1 parent 7564127 commit b43f139

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

ethstore.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,10 @@ func GetValidators(ctx context.Context, client *http.Service, stateID string) (m
187187
}
188188

189189
type BlockData struct {
190+
Version spec.DataVersion
190191
ProposerIndex phase0.ValidatorIndex
191192
Transactions []bellatrix.Transaction
192-
BaseFeePerGas [32]byte
193+
BaseFeePerGas *big.Int
193194
Deposits []*phase0.Deposit
194195
GasUsed uint64
195196
GasLimit uint64
@@ -199,6 +200,7 @@ type BlockData struct {
199200

200201
func GetBlockData(block *spec.VersionedSignedBeaconBlock) (*BlockData, error) {
201202
d := &BlockData{}
203+
d.Version = block.Version
202204
switch block.Version {
203205
case spec.DataVersionPhase0:
204206
d.Deposits = block.Phase0.Message.Body.Deposits
@@ -211,15 +213,23 @@ func GetBlockData(block *spec.VersionedSignedBeaconBlock) (*BlockData, error) {
211213
d.ProposerIndex = block.Bellatrix.Message.ProposerIndex
212214
d.GasUsed = block.Bellatrix.Message.Body.ExecutionPayload.GasUsed
213215
d.GasLimit = block.Bellatrix.Message.Body.ExecutionPayload.GasLimit
214-
d.BaseFeePerGas = block.Bellatrix.Message.Body.ExecutionPayload.BaseFeePerGas
216+
baseFeePerGasBEBytes := make([]byte, len(block.Bellatrix.Message.Body.ExecutionPayload.BaseFeePerGas))
217+
for i := 0; i < 32; i++ {
218+
baseFeePerGasBEBytes[i] = block.Bellatrix.Message.Body.ExecutionPayload.BaseFeePerGas[32-1-i]
219+
}
220+
d.BaseFeePerGas = new(big.Int).SetBytes(baseFeePerGasBEBytes)
215221
d.BlockNumber = block.Bellatrix.Message.Body.ExecutionPayload.BlockNumber
216222
d.Transactions = block.Bellatrix.Message.Body.ExecutionPayload.Transactions
217223
case spec.DataVersionCapella:
218224
d.Deposits = block.Capella.Message.Body.Deposits
219225
d.ProposerIndex = block.Capella.Message.ProposerIndex
220226
d.GasUsed = block.Capella.Message.Body.ExecutionPayload.GasUsed
221227
d.GasLimit = block.Capella.Message.Body.ExecutionPayload.GasLimit
222-
d.BaseFeePerGas = block.Capella.Message.Body.ExecutionPayload.BaseFeePerGas
228+
baseFeePerGasBEBytes := make([]byte, len(block.Capella.Message.Body.ExecutionPayload.BaseFeePerGas))
229+
for i := 0; i < 32; i++ {
230+
baseFeePerGasBEBytes[i] = block.Capella.Message.Body.ExecutionPayload.BaseFeePerGas[32-1-i]
231+
}
232+
d.BaseFeePerGas = new(big.Int).SetBytes(baseFeePerGasBEBytes)
223233
d.Withdrawals = block.Capella.Message.Body.ExecutionPayload.Withdrawals
224234
d.BlockNumber = block.Capella.Message.Body.ExecutionPayload.BlockNumber
225235
d.Transactions = block.Capella.Message.Body.ExecutionPayload.Transactions
@@ -228,7 +238,7 @@ func GetBlockData(block *spec.VersionedSignedBeaconBlock) (*BlockData, error) {
228238
d.ProposerIndex = block.Deneb.Message.ProposerIndex
229239
d.GasUsed = block.Deneb.Message.Body.ExecutionPayload.GasUsed
230240
d.GasLimit = block.Deneb.Message.Body.ExecutionPayload.GasLimit
231-
d.BaseFeePerGas = block.Deneb.Message.Body.ExecutionPayload.BaseFeePerGas.Bytes32()
241+
d.BaseFeePerGas = block.Deneb.Message.Body.ExecutionPayload.BaseFeePerGas.ToBig()
232242
d.Withdrawals = block.Deneb.Message.Body.ExecutionPayload.Withdrawals
233243
d.BlockNumber = block.Deneb.Message.Body.ExecutionPayload.BlockNumber
234244
d.Transactions = block.Deneb.Message.Body.ExecutionPayload.Transactions
@@ -488,13 +498,7 @@ func Calculate(ctx context.Context, bnAddress, elAddress, dayStr string, concurr
488498
totalTxFee.Add(totalTxFee, txFee)
489499
}
490500

491-
// base fee per gas is stored little-endian but we need it
492-
// big-endian for big.Int.
493-
var baseFeePerGasBEBytes [32]byte
494-
for i := 0; i < 32; i++ {
495-
baseFeePerGasBEBytes[i] = blockData.BaseFeePerGas[32-1-i]
496-
}
497-
baseFeePerGas := new(big.Int).SetBytes(baseFeePerGasBEBytes[:])
501+
baseFeePerGas := blockData.BaseFeePerGas
498502
burntFee := new(big.Int).Mul(baseFeePerGas, new(big.Int).SetUint64(blockData.GasUsed))
499503

500504
totalTxFee.Sub(totalTxFee, burntFee)

0 commit comments

Comments
 (0)