Skip to content

Commit

Permalink
Merge branch 'main' into mpeter/consolidate-tx-max-gas-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
franklywatson authored Feb 21, 2025
2 parents 1848004 + da6552b commit 93437a2
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 41 deletions.
6 changes: 2 additions & 4 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const BlockGasLimit uint64 = 120_000_000

const maxFeeHistoryBlockCount = 1024

var baseFeesPerGas = big.NewInt(1)

var latestBlockNumberOrHash = rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)

func SupportedAPIs(
Expand Down Expand Up @@ -852,7 +850,7 @@ func (b *BlockChainAPI) FeeHistory(
oldestBlock = (*hexutil.Big)(big.NewInt(int64(block.Height)))
}

baseFees = append(baseFees, (*hexutil.Big)(baseFeesPerGas))
baseFees = append(baseFees, (*hexutil.Big)(models.BaseFeePerGas))

rewards = append(rewards, blockRewards)

Expand Down Expand Up @@ -968,7 +966,7 @@ func (b *BlockChainAPI) prepareBlockResponse(
GasLimit: hexutil.Uint64(BlockGasLimit),
Nonce: types.BlockNonce{0x1},
Timestamp: hexutil.Uint64(block.Timestamp),
BaseFeePerGas: hexutil.Big(*baseFeesPerGas),
BaseFeePerGas: hexutil.Big(*models.BaseFeePerGas),
LogsBloom: types.LogsBloom([]*types.Log{}),
Miner: evmTypes.CoinbaseAddress.ToCommon(),
Sha3Uncles: types.EmptyUncleHash,
Expand Down
97 changes: 64 additions & 33 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type Bootstrap struct {
publishers *Publishers
collector metrics.Collector
server *api.Server
metrics *flowMetrics.Server
metrics *metricsWrapper
events *ingestion.Engine
profiler *api.ProfileServer
db *pebbleDB.DB
Expand Down Expand Up @@ -372,42 +372,13 @@ func (b *Bootstrap) StopAPIServer() {
}

func (b *Bootstrap) StartMetricsServer(ctx context.Context) error {
b.logger.Info().Msg("bootstrap starting metrics server")

b.metrics = flowMetrics.NewServer(b.logger, uint(b.config.MetricsPort))

// this logic is needed since the metric server is a component.
// we need to start and stop it manually here.

ictx, errCh := irrecoverable.WithSignaler(ctx)
b.metrics.Start(ictx)
if err := util.WaitClosed(ctx, b.metrics.Ready()); err != nil {
return fmt.Errorf("failed to start metrics server: %w", err)
}
select {
case err := <-errCh:
// there might be an error already if the startup failed
return err
default:
}

go func() {
err := <-errCh
if err != nil {
b.logger.Err(err).Msg("error in metrics server")
panic(err)
}
}()

return nil
b.metrics = newMetricsWrapper(b.logger, b.config.MetricsPort)
return b.metrics.Start(ctx)
}

func (b *Bootstrap) StopMetricsServer() {
if b.metrics == nil {
return
}
<-b.metrics.Done()
b.logger.Warn().Msg("shutting down metrics server")
b.metrics.Stop()
}

func (b *Bootstrap) StartProfilerServer(_ context.Context) error {
Expand Down Expand Up @@ -710,3 +681,63 @@ func Run(ctx context.Context, cfg config.Config, ready component.ReadyFunc) erro

return nil
}

// metricsWrapper is needed since the metric server is a component.
// We need to start and stop it manually.
type metricsWrapper struct {
*flowMetrics.Server
log zerolog.Logger
stopFN func()
}

func newMetricsWrapper(logger zerolog.Logger, port int) *metricsWrapper {
return &metricsWrapper{
Server: flowMetrics.NewServer(logger, uint(port)),
log: logger,
stopFN: nil,
}
}

func (m *metricsWrapper) Start(ctx context.Context) error {
m.log.Info().Msg("bootstrap starting metrics server")

ctx, cancel := context.WithCancel(ctx)
ictx, errCh := irrecoverable.WithSignaler(ctx)

m.Server.Start(ictx)
if err := util.WaitClosed(ctx, m.Ready()); err != nil {
cancel()
return fmt.Errorf("failed to start metrics server: %w", err)
}
select {
case err := <-errCh:
// there might be an error already if the startup failed
cancel()
return err
default:
}

go func() {
err := <-errCh
cancel()
if err != nil {
m.log.Err(err).Msg("error in metrics server")
panic(err)
}
}()

m.stopFN = cancel

return nil
}

func (m *metricsWrapper) Stop() {
if m == nil || m.stopFN == nil {
return
}
m.log.Warn().Msg("shutting down metrics server")
// context could already be cancelled, but no harm in calling cancel again.
// especially in testing scenarios.
m.stopFN()
<-m.Done()
}
4 changes: 4 additions & 0 deletions eth/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ func MarshalReceipt(
"effectiveGasPrice": (*hexutil.Big)(receipt.EffectiveGasPrice),
}

if _, ok := tx.(models.DirectCall); ok {
fields["effectiveGasPrice"] = (*hexutil.Big)(models.BaseFeePerGas)
}

if tx.To() != nil {
fields["to"] = tx.To().Hex()
}
Expand Down
5 changes: 4 additions & 1 deletion models/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
TxMaxGasLimit = uint64(50_000_000)
)

var BaseFeePerGas = big.NewInt(1)

type Transaction interface {
Hash() common.Hash
RawSignatureValues() (v *big.Int, r *big.Int, s *big.Int)
Expand Down Expand Up @@ -117,7 +119,7 @@ func (dc DirectCall) GasTipCap() *big.Int {
}

func (dc DirectCall) GasPrice() *big.Int {
return big.NewInt(0)
return BaseFeePerGas
}

func (dc DirectCall) BlobGas() uint64 {
Expand Down Expand Up @@ -232,6 +234,7 @@ func decodeTransactionEvent(event cadence.Event) (
err,
)
}
receipt.EffectiveGasPrice = BaseFeePerGas
tx = DirectCall{DirectCall: directCall}
} else {
gethTx := &gethTypes.Transaction{}
Expand Down
4 changes: 2 additions & 2 deletions models/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func Test_DecodeDirectCall(t *testing.T) {
assert.Equal(t, big.NewInt(10000000000), decTx.Value())
assert.Equal(t, uint8(gethTypes.LegacyTxType), decTx.Type())
assert.Equal(t, uint64(23_300), decTx.Gas())
assert.Equal(t, big.NewInt(0), decTx.GasPrice())
assert.Equal(t, BaseFeePerGas, decTx.GasPrice())
assert.Equal(t, uint64(0), decTx.BlobGas())
assert.Equal(t, uint64(61), decTx.Size())
}
Expand Down Expand Up @@ -273,7 +273,7 @@ func Test_UnmarshalTransaction(t *testing.T) {
assert.Equal(t, big.NewInt(10000000000), decTx.Value())
assert.Equal(t, uint8(gethTypes.LegacyTxType), decTx.Type())
assert.Equal(t, uint64(23_300), decTx.Gas())
assert.Equal(t, big.NewInt(0), decTx.GasPrice())
assert.Equal(t, BaseFeePerGas, decTx.GasPrice())
assert.Equal(t, uint64(0), decTx.BlobGas())
assert.Equal(t, uint64(61), decTx.Size())
})
Expand Down
2 changes: 1 addition & 1 deletion tests/web3js/eth_filter_endpoints_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ describe('eth_getFilterChanges', async () => {
blockNumber: '0xd',
from: '0x0000000000000000000000030000000000000000',
gas: '0x5b04',
gasPrice: '0x0',
gasPrice: '0x1',
hash: '0x71201dbf66271cedb6e87a5364b2cb84f6170e282f2b3f676196687bdf4babe0',
input: '0x',
nonce: '0x9',
Expand Down
14 changes: 14 additions & 0 deletions tests/web3js/eth_non_interactive_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ it('should get block', async () => {
assert.isString(tx.hash)
assert.equal(tx.transactionIndex, txIndex)

// COA interactions
if (tx.v === 255n) {
assert.equal(tx.gasPrice, 1n)
} else {
assert.equal(tx.gasPrice, conf.minGasPrice)
}

let txReceipt = await web3.eth.getTransactionReceipt(tx.hash)
assert.isNotNull(txReceipt)
assert.equal(txReceipt.blockNumber, block.number)
Expand All @@ -69,6 +76,13 @@ it('should get block', async () => {
assert.equal(txReceipt.transactionIndex, txIndex)
assert.isNotNull(txReceipt.from)

// COA interactions
if (tx.v === 255n) {
assert.equal(txReceipt.effectiveGasPrice, 1n)
} else {
assert.equal(txReceipt.effectiveGasPrice, conf.minGasPrice)
}

// first transaction is the COA resource creation,
// which also does the contract deployment
if (txIndex == 0) {
Expand Down

0 comments on commit 93437a2

Please sign in to comment.