Skip to content

Commit 4969b78

Browse files
authored
Add baseFeePerGas to headers sent via EthSubscribe (#2060)
* mycelo: enable websockets Makes it easier to test websocket specific operations (e.g. subscriptions) and I don't see a reason not to turn in on. * Add baseFeePerGas to headers via EthSubscribe Closes celo-org/celo-blockchain-planning#59
1 parent ebd771d commit 4969b78

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

accounts/abi/bind/backends/simulated.go

+4
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,10 @@ func (fb *filterBackend) ServiceFilter(ctx context.Context, ms *bloombits.Matche
874874
panic("not supported")
875875
}
876876

877+
func (fb *filterBackend) RealGasPriceMinimumForHeader(ctx context.Context, currencyAddress *common.Address, header *types.Header) (*big.Int, error) {
878+
return nil, fmt.Errorf("filterBackend does not implement RealGasPriceMinimumForHeader")
879+
}
880+
877881
func nullSubscription() event.Subscription {
878882
return event.NewSubscription(func(quit <-chan struct{}) error {
879883
<-quit

eth/filters/api.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"github.com/celo-org/celo-blockchain/common/hexutil"
3131
"github.com/celo-org/celo-blockchain/core/types"
3232
"github.com/celo-org/celo-blockchain/ethdb"
33+
"github.com/celo-org/celo-blockchain/internal/ethapi"
34+
"github.com/celo-org/celo-blockchain/log"
3335
"github.com/celo-org/celo-blockchain/rpc"
3436
)
3537

@@ -223,7 +225,14 @@ func (api *PublicFilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, er
223225
for {
224226
select {
225227
case h := <-headers:
226-
notifier.Notify(rpcSub.ID, h)
228+
jsonHeader := ethapi.RPCMarshalHeader(h)
229+
baseFee, err := api.backend.RealGasPriceMinimumForHeader(ctx, nil, h)
230+
if err != nil {
231+
log.Debug("Not adding baseFeePerGas to header subscription, failed to retrieve gas price minimum", "block", h.Number.Uint64(), "err", err)
232+
} else {
233+
jsonHeader["baseFeePerGas"] = (*hexutil.Big)(baseFee)
234+
}
235+
notifier.Notify(rpcSub.ID, jsonHeader)
227236
case <-rpcSub.Err():
228237
headersSub.Unsubscribe()
229238
return

eth/filters/filter.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Backend interface {
4545

4646
BloomStatus() (uint64, uint64)
4747
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
48+
RealGasPriceMinimumForHeader(ctx context.Context, currencyAddress *common.Address, header *types.Header) (*big.Int, error)
4849
}
4950

5051
// Filter can be used to retrieve and filter logs.

eth/filters/filter_system_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ func (b *testBackend) ServiceFilter(ctx context.Context, session *bloombits.Matc
156156
}()
157157
}
158158

159+
func (b *testBackend) RealGasPriceMinimumForHeader(ctx context.Context, currencyAddress *common.Address, header *types.Header) (*big.Int, error) {
160+
return nil, fmt.Errorf("testBackend does not implement RealGasPriceMinimumForHeader")
161+
}
162+
159163
// TestBlockSubscription tests if a block subscription returns block hashes for posted chain events.
160164
// It creates multiple subscriptions:
161165
// - one at the start and should receive all posted chain events and a second (blockHashes)

mycelo/cluster/node.go

+9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ func (nc *NodeConfig) RPCPort() int64 {
4040
return int64(8545 + nc.Number)
4141
}
4242

43+
// RPCPort is the rpc port this node will use
44+
func (nc *NodeConfig) WebsocketPort() int64 {
45+
return int64(9545 + nc.Number)
46+
}
47+
4348
// NodePort is the node port this node will use
4449
func (nc *NodeConfig) NodePort() int64 {
4550
return int64(30303 + nc.Number)
@@ -165,6 +170,10 @@ func (n *Node) Run(ctx context.Context) error {
165170
"--http.addr", "127.0.0.1",
166171
"--http.port", strconv.FormatInt(n.RPCPort(), 10),
167172
"--http.api", "eth,net,web3,debug,admin,personal,istanbul,txpool",
173+
"--ws",
174+
"--ws.addr", "127.0.0.1",
175+
"--ws.port", strconv.FormatInt(n.WebsocketPort(), 10),
176+
"--ws.api", "eth,net,web3,debug,admin,personal,istanbul,txpool",
168177
// "--nodiscover", "--nousb ",
169178
"--unlock", addressToUnlock,
170179
"--password", n.pwdFile(),

0 commit comments

Comments
 (0)