Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Discord Bot #53

Merged
merged 37 commits into from
Jul 5, 2023
Merged

Basic Discord Bot #53

merged 37 commits into from
Jul 5, 2023

Conversation

sveitser
Copy link
Collaborator

@sveitser sveitser commented Jun 20, 2023

Limitations

  • There is no persistence so during downtime requests will be lost. However the discord users would see that the bot does not respond to messages like it usually does.
  • Funding logic only runs at the start of the faucet. The faucet will always use the available account with the highest available balance for transfers, so I think refunding is unlikely to be necessary.
  • There is currently no functionality to rebalance funds when decreasing the number of clients. It shouldn't take more than 15 minutes to write a client for that though.
  • The CI currently can't run successfully because we need the faucet docker image that doesn't exist on main. The command to pull docker images fails as a result and the test that uses the zkevm-node can't work.

TODO

  • Docker container.
  • Add to compose env.
  • Documentation for faucet setup.
  • Web server with health check.

Close EspressoSystems/espresso-sequencer#373

Base automatically changed from ma/eth-client-to-generate-load to main June 22, 2023 18:40
Not really working at the moment beyond a few transfers. Suspect there's
some kind of deadlock and may have to change the design a bit.
Popping from two Vecs is a bad idea.
The zkevm websocket server runs on a different port than the http
server. Other than that there are no surprises.
inflight_clients: HashMap<Address, Arc<Middleware>>,
// Funding wallets has priority, these transfer requests must be pushed to
// the front.
transfer_queue: VecDeque<Transfer>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be somewhat simpler to use a channel for this transfer queue as well or just get rid of it completely. Currently for internal funding transfers the faucet will add to this queue directly and the external faucet transfer get added to this queue via the faucet_receiver.

faucet/src/lib.rs Outdated Show resolved Hide resolved
faucet/src/main.rs Outdated Show resolved Hide resolved
- Fix docker compose demo.
- Include change of zkevm-node to panic on startup.
- Make it possible to run without discord faucet for local testing.
@sveitser
Copy link
Collaborator Author

The CI currently fails because it needs the container that is only available from main.

This reverts commit 17d38ac.

This doesn't work:

    The workflow is not valid. .github/workflows/build.yml (Line: 19,
    Col: 3): The workflow must contain at least one job with no
    dependencies.
@sveitser sveitser marked this pull request as ready for review July 3, 2023 18:05
faucet/src/discord.rs Outdated Show resolved Hide resolved
@sveitser
Copy link
Collaborator Author

sveitser commented Jul 3, 2023

For the CI I suggest we just merge it and then if necessary make new PRs to fix it. It's quite involved to change the CI workflows so that it can use the docker containers built from this repo directly so I don't think it's worth it at this stage.

let required = match transfer {
// Double the faucet amount to be on the safe side regarding gas.
TransferRequest::Faucet { amount, .. } => amount * 2,
TransferRequest::Funding { .. } => self.total_balance / self.clients.len(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. The balance here should be looking at the total balance and not the balance that is currently in the pool of available clients. Maybe it's better to keep all the clients in the pool but mark them as available or not, instead of moving the in and out of the pool.

Copy link
Collaborator Author

@sveitser sveitser Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in 8d82f76

.env Show resolved Hide resolved
faucet/src/discord.rs Outdated Show resolved Hide resolved
faucet/src/discord.rs Outdated Show resolved Hide resolved
Comment on lines +88 to +90
let intents = GatewayIntents::GUILD_MESSAGES
| GatewayIntents::DIRECT_MESSAGES
| GatewayIntents::MESSAGE_CONTENT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think to avoid spam we should restrict the bot to listen only to messages in a specific channel (and maybe DMs). We don't want it responding to every message in any channel that happens to include a valid address (e.g. someone asks for help in a support channel and happens to include their address). Not sure how or where to do that.

Copy link
Collaborator Author

@sveitser sveitser Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we can tell discord to only have the bot get messages from the faucet channel but it turns out that is way more involved than I thought and one has to remove the bot from each channel that it shouldn't respond to. Some discussion here: https://support.discord.com/hc/en-us/community/posts/360045778711-Restrict-bots-to-certain-channels-

The easiest for us would be to filter by channel ID in rust but this is a bit tedious to configure: we need to add an env var with the channel ID.

I think a more idiomatic discord way of doing it may be to

  1. add a command to the bot, so users would have to write for example /faucet 0x123... instead of just posting the address
  2. only allow that command in the faucet channel.

Unfortunately after half an hour I'm still not sure how to create these commands with serenity.

Another solution that might be okay, but still tedious. We can remove the bots permissions to read messages for all channel categories except for a channel category that only contains the faucet channel.

Copy link
Collaborator Author

@sveitser sveitser Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got this slash command thing to work after all. It also includes some docs for the users and AFAICT does not require any extra config in the code.

2023-07-04_14-10

The discord UI can be used to restrict usage of the bot to a channel

2023-07-04_14-22

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is in 4d54dd9

faucet/src/faucet.rs Show resolved Hide resolved
faucet/src/faucet.rs Show resolved Hide resolved
faucet/src/faucet.rs Outdated Show resolved Hide resolved
faucet/src/faucet.rs Outdated Show resolved Hide resolved
faucet/src/faucet.rs Show resolved Hide resolved
Require a wallet to have more than the average initiial balance of all
the faucet wallets.

- Log an error when we retry for a transaction receipt of a transactions
  that's already in a block.
Avoid holding guards longer than necessary.
@sveitser sveitser requested a review from jbearer July 4, 2023 17:28
Copy link
Member

@jbearer jbearer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sveitser
Copy link
Collaborator Author

sveitser commented Jul 5, 2023

Will merge to get docker image built. Then fix what's necessary.

@sveitser sveitser merged commit 8acbe40 into main Jul 5, 2023
0 of 3 checks passed
@sveitser sveitser deleted the ma/zkevm-faucet branch July 5, 2023 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a discord faucet for polygon-zkevm funding
2 participants