hirosystems / stacks-blockchain-api

API for the Stacks blockchain
https://stacks-blockchain-api.vercel.app
GNU General Public License v3.0
170 stars 108 forks source link

Faucet ratelimit not correct #1938

Open CharlieC3 opened 2 months ago

CharlieC3 commented 2 months ago

Describe the bug When using the STX faucet, a ratelimit is applied to the request. However, the condition which determines when to block or allow a request pulls its non-stacking and stacking faucet request historical data from the same source, resulting in some requests being blocked when they should not be.

To Reproduce Steps to reproduce the behavior:

  1. Request non-stacking amount from faucet to a testnet Stacks address and wait for the TX to settle. This will be allowed
  2. Request a stacking amount from faucet to the same Stacks address. This will be denied despite a stacking faucet request never being sent before.

Expected behavior A faucet request should only rate limit someone if they've made a successful faucet request in like-kind (stacking=false vs stacking=true)

Console log

04/10/2024, 10:36:59.413 AM request completed -> /extended/v1/faucets/stx?address=ST1X0WKFDX7K2BD6FK4XJMCX3M4BZETDKWF353FGV -> 200 -> POST
04/10/2024, 11:38:00.303 AM STX faucet rate limit hit for address ST1X0WKFDX7K2BD6FK4XJMCX3M4BZETDKWF353FGV
04/10/2024, 11:38:00.304 AM request completed -> /extended/v1/faucets/stx?address=ST1X0WKFDX7K2BD6FK4XJMCX3M4BZETDKWF353FGV&stacking=true -> 429 -> POST
04/10/2024, 11:46:52.351 AM STX faucet rate limit hit for address ST1X0WKFDX7K2BD6FK4XJMCX3M4BZETDKWF353FGV
04/10/2024, 11:46:52.352 AM request completed -> /extended/v1/faucets/stx?address=ST1X0WKFDX7K2BD6FK4XJMCX3M4BZETDKWF353FGV&stacking=true -> 429 -> POST
04/10/2024, 11:47:40.629 AM STX faucet rate limit hit for address ST1X0WKFDX7K2BD6FK4XJMCX3M4BZETDKWF353FGV
04/10/2024, 11:47:40.630 AM request completed -> /extended/v1/faucets/stx?address=ST1X0WKFDX7K2BD6FK4XJMCX3M4BZETDKWF353FGV&stacking=true -> 429 -> POST