Skip to content

Commit

Permalink
builder: implement BEP322 builder-api (bnb-chain#7)
Browse files Browse the repository at this point in the history
* feat: mev-builder

* consesus: add a interface to set validator at runtime
* core/txpool: add bundlepool to maintain bundle txs
* core/type: define bundle
* internal/ethapi: add sendBundle, bundlePrice, unregis
* ethclient: add SendBundle
* miner: add fillTransacitonsAndBundles, add Bidder to sendBid to validators
* add README.builder.md
---------

Co-authored-by: raina <irunert@gmail.com>
  • Loading branch information
pythonberg1997 and irrun committed Mar 13, 2024
1 parent 7169e2b commit 884dad6
Show file tree
Hide file tree
Showing 27 changed files with 1,861 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ truffle-test:
docker build . -f ./docker/Dockerfile --target bsc -t bsc
docker build . -f ./docker/Dockerfile.truffle -t truffle-test
docker-compose -f ./tests/truffle/docker-compose.yml up genesis
docker-compose -f ./tests/truffle/docker-compose.yml up -d bsc-rpc bsc-validator1
docker-compose -f ./tests/truffle/docker-compose.yml up -d bsc-rpc
sleep 30
docker-compose -f ./tests/truffle/docker-compose.yml up --exit-code-from truffle-test truffle-test
docker-compose -f ./tests/truffle/docker-compose.yml down
Expand Down
45 changes: 45 additions & 0 deletions README.builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[bsc readme](README.original.md)

# BSC Builder

This project implements the BEP-322: Builder API Specification for BNB Smart Chain.

This project represents a minimal implementation of the protocol and is provided as is. We make no guarantees regarding its functionality or security.

See also: https://github.com/bnb-chain/BEPs/pull/322

# Usage

Builder-related settings are configured in the `config.toml` file. The following is an example of a `config.toml` file:

```
[Eth.Miner.Mev]
Enabled = false
ValidatorCommission = 100
BidSimulationLeftOver = 50
BuilderEnabled = true
BuilderAccount = {{BUILDER_ADDRESS}}
[[Eth.Miner.Mev.Validators]]
Address = {{VALIDATOR_ADDRESS}}
URL = {{VALIDATOR_URL}}
...
```

- `Enabled`: Whether to enable validator mev.
- `BuilderEnabled`: Whether to enable the builder mev.
- `BuilderAccount`: The account address to unlock of the builder.
- `BidSimulationLeftOver`: The left over of the bid simulation.
- `Validators`: A list of validators to bid for.
- `Address`: The address of the validator.
- `URL`: The URL of the validator.

## License

The bsc library (i.e. all code outside of the `cmd` directory) is licensed under the
[GNU Lesser General Public License v3.0](https://www.gnu.org/licenses/lgpl-3.0.en.html),
also included in our repository in the `COPYING.LESSER` file.

The bsc binaries (i.e. all code inside of the `cmd` directory) is licensed under the
[GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html), also
included in our repository in the `COPYING` file.
1 change: 1 addition & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,5 @@ type PoSA interface {
GetFinalizedHeader(chain ChainHeaderReader, header *types.Header) *types.Header
VerifyVote(chain ChainHeaderReader, vote *types.VoteEnvelope) error
IsActiveValidatorAt(chain ChainHeaderReader, header *types.Header, checkVoteKeyFn func(bLSPublicKey *types.BLSPublicKey) bool) bool
SetValidator(validator common.Address)
}
11 changes: 11 additions & 0 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,17 @@ func (p *Parlia) GetFinalizedHeader(chain consensus.ChainHeaderReader, header *t
return chain.GetHeader(snap.Attestation.SourceHash, snap.Attestation.SourceNumber)
}

// SetValidator set the validator of parlia engine
// It is used for builder
func (p *Parlia) SetValidator(val common.Address) {
if val == (common.Address{}) {
return
}
p.lock.Lock()
defer p.lock.Unlock()
p.val = val
}

// =========================== utility function ==========================
func (p *Parlia) backOffTime(snap *Snapshot, header *types.Header, val common.Address) uint64 {
if snap.inturn(val) {
Expand Down
Loading

0 comments on commit 884dad6

Please sign in to comment.