Skip to content

Commit

Permalink
Merge branch 'develop' into hotfix/sdk-mnt
Browse files Browse the repository at this point in the history
  • Loading branch information
Sha3nS authored Aug 16, 2023
2 parents ea0b2f6 + 894f76d commit 13a045f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 6 deletions.
4 changes: 4 additions & 0 deletions gas-oracle/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash

COPY ./gas-oracle /gas-oracle
COPY ./bss-core /bss-core
COPY ./l2geth /l2geth
COPY ./metrics /metrics
COPY ./fraud-proof /fraud-proof

COPY ./gas-oracle/docker.go.work /go/go.work

RUN cd /gas-oracle && make gas-oracle
Expand Down
7 changes: 7 additions & 0 deletions gas-oracle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ module github.com/mantlenetworkio/mantle/gas-oracle
go 1.18

replace github.com/mantlenetworkio/mantle/bss-core => ../bss-core
replace github.com/mantlenetworkio/mantle/l2geth => ../l2geth

require (
cloud.google.com/go/kms v1.11.0
github.com/ethereum/go-ethereum v1.10.26
github.com/go-resty/resty/v2 v2.7.0
github.com/mantlenetworkio/mantle/bss-core v0.0.0
github.com/mantlenetworkio/mantle/l2geth v0.0.0
github.com/stretchr/testify v1.8.4
github.com/urfave/cli v1.22.14
google.golang.org/api v0.126.0
Expand All @@ -19,7 +21,9 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.0.1 // indirect
github.com/VictoriaMetrics/fastcache v1.9.0 // indirect
github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
Expand All @@ -32,6 +36,7 @@ require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/decred/dcrd/hdkeychain/v3 v3.0.0 // indirect
github.com/deepmap/oapi-codegen v1.8.2 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/getsentry/sentry-go v0.12.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.1 // indirect
Expand Down Expand Up @@ -66,6 +71,8 @@ require (
github.com/rjeczalik/notify v0.9.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 // indirect
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
Expand Down
11 changes: 11 additions & 0 deletions gas-oracle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKS
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0=
github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847 h1:rtI0fD4oG/8eVokGVPYJEW1F88p1ZNgXiEIs9thEE4A=
github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand All @@ -58,6 +60,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c=
github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y=
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
Expand Down Expand Up @@ -129,6 +133,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts=
github.com/edsrzf/mmap-go v1.1.0 h1:6EUwBLQ/Mcr1EYLE4Tn1VdW1A4ckqCQWZBw8Hr0kjpQ=
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4=
github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -456,6 +462,10 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA=
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 h1:gIlAHnH1vJb5vwEjIp5kBj/eu99p/bl0Ay2goiPe5xE=
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw=
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 h1:njlZPzLwU639dk2kqnCPPv+wNjq7Xb6EfUxe/oX0/NM=
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down Expand Up @@ -605,6 +615,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
3 changes: 3 additions & 0 deletions gas-oracle/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var (
DaFeeGauge metrics.Gauge
// OverHeadGauge over_head, amortized cost of batch submission per transaction
OverHeadGauge metrics.Gauge
// OverHeadGauge over_head, amortized cost of batch submission per transaction
OverHeadUpdateGauge metrics.Gauge
// L1GasPriceGauge l1_base_fee + l1_priority_fee
L1GasPriceGauge metrics.Gauge

Expand All @@ -49,6 +51,7 @@ func InitAndRegisterStats(r metrics.Registry) {
GasOracleStats.FeeScalarGauge = metrics.NewRegisteredGauge("fee_scalar", r)
GasOracleStats.DaFeeGauge = metrics.NewRegisteredGauge("da_fee", r)
GasOracleStats.OverHeadGauge = metrics.NewRegisteredGauge("over_head", r)
GasOracleStats.OverHeadUpdateGauge = metrics.NewRegisteredGauge("over_head_update", r)
GasOracleStats.L1GasPriceGauge = metrics.NewRegisteredGauge("l1_gas_price", r)

// stats for gas oracle version
Expand Down
13 changes: 12 additions & 1 deletion gas-oracle/oracle/base_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ func wrapUpdateBaseFee(l1Backend bind.ContractTransactor, l2Backend DeployContra
if err != nil {
return nil, err
}

// initialize some metrics
// initialize fee scalar from contract
feeScalar, err := contract.Scalar(&bind.CallOpts{
Context: context.Background(),
})
if err != nil {
return nil, err
}
ometrics.GasOracleStats.FeeScalarGauge.Update(feeScalar.Int64())

return func() error {
baseFee, err := contract.L1BaseFee(&bind.CallOpts{
Context: context.Background(),
Expand All @@ -84,7 +95,7 @@ func wrapUpdateBaseFee(l1Backend bind.ContractTransactor, l2Backend DeployContra
if err != nil {
return err
}
// Update faa scalar metrics
// Update fee scalar metrics
ometrics.GasOracleStats.FeeScalarGauge.Update(feeScalar.Int64())

// NOTE this will return base multiple with coin ratio
Expand Down
11 changes: 7 additions & 4 deletions gas-oracle/oracle/gas_price_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (g *GasPriceOracle) OverHeadLoop() {
db, height := readGasOracleSyncHeight()
log.Info("ReadGasOracleSyncHeight", "height", height)
// set channel
stateBatchAppendChan := make(chan *bindings.StateCommitmentChainStateBatchAppended, 10)
stateBatchAppendChan := make(chan *bindings.StateCommitmentChainStateBatchAppended, 1)

// set context
ctcTotalBatches, err := g.ctcBackend.GetTotalBatches(&bind.CallOpts{})
Expand All @@ -229,7 +229,7 @@ func (g *GasPriceOracle) OverHeadLoop() {
continue
}
// repeat query latest block is not allowed
if height != nil && height.Uint64() != 0 && height.Uint64() == latestHeader.Number.Uint64() {
if height != nil && height.Uint64() != 0 && height.Uint64() >= latestHeader.Number.Uint64() {
continue
}
if height == nil || height.Uint64() == 0 {
Expand All @@ -247,11 +247,14 @@ func (g *GasPriceOracle) OverHeadLoop() {
case stateBatchAppendChan <- iter.Event:
log.Info("write event into channel", "channel length is", len(stateBatchAppendChan))
default:
log.Error("write too many event into channel, increase channel length")
// discard additional event to process the last one
<-stateBatchAppendChan
stateBatchAppendChan <- iter.Event
log.Warn("write additional event into channel, will ignore prev events")
}
}
_ = writeGasOracleSyncHeight(db, latestHeader.Number)
height = latestHeader.Number
height = latestHeader.Number.Add(latestHeader.Number, big.NewInt(1))
log.Info("Update synced height", "height", height)
case ev := <-stateBatchAppendChan:
currentCtcBatches, err := g.ctcBackend.GetTotalBatches(&bind.CallOpts{})
Expand Down
7 changes: 6 additions & 1 deletion gas-oracle/oracle/overhead.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ func wrapUpdateOverhead(l2Backend DeployContractBackend, cfg *Config) (func(*big
if err != nil {
return err
}

ometrics.GasOracleStats.OverHeadUpdateGauge.Inc(1)
// skip update if overhead is not changed
if overhead.Cmp(newOverheadLevel) == 0 {
log.Info("skip update overhead", "overhead", overhead)
return nil
}
// Use the configured gas price if it is set,
// otherwise use gas estimation
if cfg.gasPrice != nil {
Expand Down

0 comments on commit 13a045f

Please sign in to comment.