Skip to content

Commit 4d85feb

Browse files
committed
(BIDS-2872) wip
1 parent 300f617 commit 4d85feb

File tree

8 files changed

+138
-79
lines changed

8 files changed

+138
-79
lines changed

cmd/explorer/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ func main() {
607607
router.Use(metrics.HttpMiddleware)
608608
}
609609

610-
ratelimit.Init(utils.Config.RedisSessionStoreEndpoint, ratelimit.DefaultRequestCollector)
610+
ratelimit.Init()
611611
router.Use(ratelimit.HttpMiddleware)
612612

613613
n := negroni.New(negroni.NewRecovery())

cmd/misc/main.go

+1-12
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func main() {
393393
case "fix-ens-addresses":
394394
err = fixEnsAddresses(erigonClient)
395395
case "update-ratelimits":
396-
err = updateRatelimits()
396+
ratelimit.DBUpdater()
397397
default:
398398
utils.LogFatal(nil, fmt.Sprintf("unknown command %s", opts.Command), 0)
399399
}
@@ -1936,14 +1936,3 @@ func reExportSyncCommittee(rpcClient rpc.Client, p uint64, dryRun bool) error {
19361936
return tx.Commit()
19371937
}
19381938
}
1939-
1940-
func updateRatelimits() error {
1941-
for {
1942-
err := ratelimit.DBUpdate()
1943-
if err != nil {
1944-
logrus.WithError(err).Errorf("error in updateRatelimits")
1945-
}
1946-
time.Sleep(time.Second * 10)
1947-
}
1948-
return nil
1949-
}

db/migrations/20240125120000_add_ratelimits.sql

+18-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS
3333
endpoint TEXT NOT NULL,
3434
method TEXT NOT NULL,
3535
params TEXT NOT NULL,
36-
weight INT NOT NULL DEFAULT 0,
36+
weight INT NOT NULL DEFAULT 1,
3737
valid_from TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT TO_TIMESTAMP(0),
3838
PRIMARY KEY (endpoint, valid_from)
3939
);
@@ -49,6 +49,19 @@ CREATE TABLE IF NOT EXISTS
4949
valid_from TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT TO_TIMESTAMP(0),
5050
PRIMARY KEY (name, valid_from)
5151
);
52+
53+
SELECT 'up SQL query - add table api_products';
54+
CREATE TABLE IF NOT EXISTS
55+
api_stats (
56+
ts TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT NOW(),
57+
user_id INT NOT NULL,
58+
api_key VARCHAR(256) NOT NULL,
59+
endpoint TEXT NOT NULL,
60+
count INT NOT NULL,
61+
PRIMARY KEY (ts, user_id, api_key, endpoint)
62+
);
63+
64+
CREATE INDEX IF NOT EXISTS idx_api_stats_ts_user_id ON api_stats (ts, user_id);
5265
-- +goose StatementEnd
5366

5467
-- +goose Down
@@ -65,4 +78,8 @@ SELECT 'down SQL query - drop table api_weights';
6578
DROP TABLE IF EXISTS api_weights;
6679
SELECT 'down SQL query - drop table api_products';
6780
DROP TABLE IF EXISTS api_products;
81+
SELECT 'down SQL query - drop table api_stats';
82+
DROP TABLE IF EXISTS api_stats;
83+
SELECT 'down SQL query - drop index idx_api_stats_ts_user_id';
84+
DROP INDEX IF EXISTS idx_api_stats_ts_user_id;
6885
-- +goose StatementEnd

local-deployment/network-params.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"electra_fork_epoch": 999999999
2727
},
2828
"global_client_log_level": "info",
29-
"start_tx_spammer": true,
29+
"start_tx_spammer": false,
3030
"start_blob_spammer": false
3131
}
3232

local-deployment/provision-explorer-config.sh

-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ frontend:
101101
sapphire: price_sapphire
102102
emerald: price_emerald
103103
diamond: price_diamond
104-
custom1: price_custom1
105-
custom2: price_custom2
106104
107105
indexer:
108106
# fullIndexOnStartup: false # Perform a one time full db index on startup

local-deployment/run.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ fn_sql() {
4343
}
4444

4545
fn_redis() {
46-
docker compose exec redis-sessions redis-cli
46+
if [ -z "${1}" ]; then
47+
docker compose exec redis-sessions redis-cli
48+
else
49+
docker compose exec redis-sessions redis-cli "$@"
50+
fi
4751
#redis-cli -h localhost -p $REDIS_PORT
4852
}
4953

0 commit comments

Comments
 (0)