Skip to content

Implement BEP-592: Non-Consensus Based Block-Level Access List#3334

Merged
zzzckck merged 31 commits intobnb-chain:feature_balfrom
zzzckck:zzzckck/feature_bal_official
Sep 23, 2025
Merged

Implement BEP-592: Non-Consensus Based Block-Level Access List#3334
zzzckck merged 31 commits intobnb-chain:feature_balfrom
zzzckck:zzzckck/feature_bal_official

Conversation

@zzzckck
Copy link
Collaborator

@zzzckck zzzckck commented Sep 1, 2025

Description

This PR implements BEP-592: Non-Consensus Based Block-Level Access List to improve block execution performance. The implementation introduces a block access list (BAL) feature that tracks account and storage access during transaction execution, enabling efficient prefetching of state data.

Key changes include:

  • Implementation of BAL data structures for generation, propagation, and usage phases
  • P2P protocol enhancements (BSC/3) to support BAL transmission between peers
  • Integration with mining, state management, and prefetching systems
image

1.About Code

a.BAL lifecycle
Each BAL will mainly have three stages: Generation, Propagation and Prefetch. Each stage would have a data structure to represent.

  • Stage#1: BAL generation: validator will generate the BAL data during mining phase
// BlockAccessListRecord & AccountAccessListRecord are used to record access list during Tx execution.
type AccountAccessListRecord struct {
	TxIndex      uint32 // index of the first transaction in the block that accessed the account
	StorageItems map[common.Hash]StorageAccessItem
}

type BlockAccessListRecord struct {
	Version  uint32 // Version of the access list format
	Accounts map[common.Address]AccountAccessListRecord
}
  • Stage#2: BAL propagation
    BAL will be encoded before propagation, it is represented by BlockAccessListEncode
// StorageAccessItem is a single storage key that is accessed in a block.
type StorageAccessItem struct {
	TxIndex uint32 // index of the first transaction in the block that accessed the storage
	Dirty   bool   // true if the storage was modified in the block, false if it was read only
	Key     common.Hash
}

// AccountAccessListEncode & BlockAccessListEncode are for BAL serialization.
type AccountAccessListEncode struct {
	TxIndex      uint32 // index of the first transaction in the block that accessed the account
	Address      common.Address
	StorageItems []StorageAccessItem
}

type BlockAccessListEncode struct {
	Version  uint32 // Version of the access list format
	Number   uint64      // number of the block that the BAL is for
	Hash     common.Hash // hash of the block that the BAL is for
	SignData []byte // sign data for BAL
	Accounts []AccountAccessListEncode
}
  • 3.BAL Prefetch
    Current BAL is mainly used during prefetch, so the data structure would be:
// TxAccessListPrefetch & BlockAccessListPrefetch are for BAL prefetch
type StorageAccessItemPrefetch struct {
	Dirty bool
	Key   common.Hash
}

type TxAccessListPrefetch struct {
	Accounts map[common.Address][]StorageAccessItemPrefetch
}

type BlockAccessListPrefetch struct {
	AccessListItems map[uint32]TxAccessListPrefetch
}

b.BAL Prune
In order to avoid adding extra complexity to the current freezer module, BAL will only be kept in KVDB, but only for the recent FullImmutabilityThreshold(360_000) blocks, elder BAL will be deleted.

c.BSC/3 P2P protocol
BSC/3 would be used to indicate the BAL capability of the remote peer, only peer with bsc/3 protocol will be able to handle BAL data.

2.Try It:

Currently, validator is the only producer of BAL, so validator needs to be upgraded first, then the connected full node can get the BAL data and use it to accelerate it syncing performance.

Enable BAL both on validator and connected full nodes, it can be done by running with flag --enablebal, or update the config.toml:

...
[Node]
EnableBAL = true
...

@zzzckck zzzckck marked this pull request as draft September 1, 2025 02:38
@zzzckck zzzckck force-pushed the zzzckck/feature_bal_official branch from 52c6fac to 3b0c13a Compare September 4, 2025 01:56
@zzzckck zzzckck requested a review from Copilot September 4, 2025 14:25

This comment was marked as outdated.

@zzzckck zzzckck changed the title Draft: bal Implement BEP-592: Non-Consensus Based Block-Level Access List, Sep 5, 2025
@zzzckck zzzckck changed the title Implement BEP-592: Non-Consensus Based Block-Level Access List, Implement BEP-592: Non-Consensus Based Block-Level Access List Sep 5, 2025
@zzzckck zzzckck requested a review from Copilot September 8, 2025 06:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements BEP-592: Non-Consensus Based Block-Level Access List to improve block execution performance. The implementation introduces a block access list (BAL) feature that tracks account and storage access during transaction execution, enabling efficient prefetching of state data.

Key changes include:

  • Implementation of BAL data structures for generation, propagation, and usage phases
  • P2P protocol enhancements (BSC/3) to support BAL transmission between peers
  • Integration with mining, state management, and prefetching systems

Reviewed Changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
core/types/block.go Adds BAL data structures and methods for block access list handling
core/state/statedb.go Implements BAL recording during state access and prefetch functionality
core/state_prefetcher.go Adds BAL-based prefetching logic for snapshot and trie caches
eth/protocols/eth/protocol.go Updates NewBlockPacket to include optional BAL field
eth/protocols/bsc/protocol.go Adds BSC/3 protocol version and BAL support in BlockData
core/rawdb/accessors_chain.go Implements BAL storage and retrieval functions
consensus/parlia/parlia.go Adds BAL signing and verification methods
node/config.go Adds EnableBAL configuration option
miner/worker.go Integrates BAL generation during block creation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@zzzckck zzzckck marked this pull request as ready for review September 8, 2025 07:22
@zzzckck zzzckck force-pushed the zzzckck/feature_bal_official branch from b25c8cf to 329fc73 Compare September 8, 2025 09:07
@zzzckck zzzckck changed the base branch from develop to feature_bal September 8, 2025 09:14
@zzzckck zzzckck force-pushed the zzzckck/feature_bal_official branch from d314b7b to 8efaaaa Compare September 11, 2025 07:29
@zzzckck zzzckck force-pushed the zzzckck/feature_bal_official branch 2 times, most recently from f0757c6 to 2e37b3d Compare September 15, 2025 02:43
@zzzckck zzzckck force-pushed the zzzckck/feature_bal_official branch from 68f6874 to e2644dd Compare September 23, 2025 06:06
@zzzckck zzzckck merged commit f4467d1 into bnb-chain:feature_bal Sep 23, 2025
1 check failed
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.

4 participants