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

builder: implement BEP322 builder-api #7

Merged
merged 6 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading