Skip to content

Polish validator 2 --- self readcodes.#34

Draft
will-2012 wants to merge 11 commits intobnb-developfrom
polish-validator-2
Draft

Polish validator 2 --- self readcodes.#34
will-2012 wants to merge 11 commits intobnb-developfrom
polish-validator-2

Conversation

@will-2012
Copy link
Owner

Description

add a description of your changes here...

Rationale

tell us why we need these changes...

Example

add an example CLI or API response...

Changes

Notable changes:

  • add each change in a bullet point here
  • ...

Potential Impacts

  • add potential impacts for other components here
  • ...

@will-2012 will-2012 marked this pull request as draft September 8, 2025 06:24
@will-2012 will-2012 changed the title Polish validator 2 --- readcodes. Polish validator 2 --- self readcodes. Sep 8, 2025
@@ -0,0 +1,33 @@
#!/usr/bin/env cargo
Copy link
Owner Author

Choose a reason for hiding this comment

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

生成私钥.

if left_over_ms >= period_ms {
warn!("Delay invalid argument: left_over_ms={}, period_ms={}", left_over_ms, period_ms);
} else if left_over_ms >= delay_ms {
delay_ms = 0;
Copy link
Owner Author

Choose a reason for hiding this comment

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


pub fn seal(self, block: BscBlock) -> Result<SealedBlock<BscBlock>, ConsensusError> {
pub fn seal(&self, block: BscBlock) -> Result<SealedBlock<BscBlock>, ConsensusError> {
let header = block.header();
Copy link
Owner Author

Choose a reason for hiding this comment

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


/// Returns true if `block_number` is the last block of the current turn window.
/// When turn_length is 1 (pre-Bohr), every block is considered last in turn.
pub fn last_block_in_one_turn(&self, block_number: u64) -> bool {
Copy link
Owner Author

Choose a reason for hiding this comment

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

+ Sync
+ 'static,
{
pub fn new(
Copy link
Owner Author

Choose a reason for hiding this comment

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

关注下什么地方调用的.

}

/// Collect transactions from the transaction pool
async fn collect_transactions(
Copy link
Owner Author

Choose a reason for hiding this comment

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

参考payload builder实现

let handle = ImportHandle::new(to_import.clone(), import_outcome);

// Expose the sender globally so that the miner can submit newly mined blocks
if crate::shared::set_block_import_sender(to_import.clone()).is_err() {
Copy link
Owner Author

Choose a reason for hiding this comment

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

block broadcast channel?


let expected_hash = block.header.hash_slow();
let sealed_block = block.seal_slow();
let sealed_block = match &self.sealed_block {
Copy link
Owner Author

Choose a reason for hiding this comment

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

错了,todo revert.


### Transaction Collection

- Fetches best transactions from the transaction pool
Copy link
Owner Author

Choose a reason for hiding this comment

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

是不是需要模拟执行?? --- 看看eth怎么搞的

Copy link
Owner Author

Choose a reason for hiding this comment

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

注意system tx.

Copy link
Owner Author

Choose a reason for hiding this comment

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

这个过程,正常还需要监听最新head.

Copy link
Owner Author

Choose a reason for hiding this comment

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

ctx.provider().canonical_state_stream() 监听head逻辑?


- Fetches best transactions from the transaction pool
- Respects block gas limit constraints
- Currently simplified - full transaction processing to be implemented
Copy link
Owner Author

Choose a reason for hiding this comment

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

什么意思?


### 1. Transaction Processing
```rust
// TODO: Implement proper transaction cloning based on transaction type
Copy link
Owner Author

Choose a reason for hiding this comment

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

关注这几个todo... 其实想的很清楚了.

2. Calculate optimal mining time based on turn
3. Collect transactions from pool
4. Build and seal block using Parlia consensus
5. Submit block (when implemented)
Copy link
Owner Author

Choose a reason for hiding this comment

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

可能需要交给引擎api,内部有最长链判断等等 --- 将来这部分也需要修改,FF有些判定、reorg等逻辑貌似也在这部分..并且与eth是有差异的.


### With reth-bsc Components

- **Engine API**: Integrates with `BscPayloadServiceBuilder`
Copy link
Owner Author

Choose a reason for hiding this comment

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

不一定需要吧 --- 具体看build payload是自己实现,还是依赖engine-api下的payload builder. 貌似大概率,应该自己实现,因为和system tx等等相关???--- 再想想

### With reth-bsc Components

- **Engine API**: Integrates with `BscPayloadServiceBuilder`
- **Consensus**: Uses existing Parlia consensus logic
Copy link
Owner Author

Choose a reason for hiding this comment

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

逻辑补全,缺各种prepare、seal等逻辑

## Next Steps

1. **Complete Transaction Integration**: Implement proper transaction collection and processing
2. **Block Submission**: Connect to engine API or direct chain import
Copy link
Owner Author

Choose a reason for hiding this comment

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

对 是个问题;大概率走engine-api. 不然最长链判断、内存状态维护等等,那一坨逻辑是相当多的.


🚧 **In Progress**:
- Configuration file loading
- Transaction processing
Copy link
Owner Author

Choose a reason for hiding this comment

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

me

Copy link
Owner Author

Choose a reason for hiding this comment

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

主体还是要参考 default_ethereum_payload !!!

🚧 **In Progress**:
- Configuration file loading
- Transaction processing
- Block submission to chain
Copy link
Owner Author

Choose a reason for hiding this comment

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

clyde


## 🚨 Important Notes

- **Auto-generated keys are for DEVELOPMENT only**
Copy link
Owner Author

Choose a reason for hiding this comment

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

note.


- **Auto-generated keys are for DEVELOPMENT only**
- **Save the generated keys if you want to reuse the same validator identity**
- **Mining will work but blocks may not be accepted without proper validator registration**
Copy link
Owner Author

Choose a reason for hiding this comment

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

对于测试,我理解这个就够用了.


/// Use development chain with auto-generated validators
#[arg(long = "bsc-dev")]
pub dev_mode: bool,
Copy link
Owner Author

Choose a reason for hiding this comment

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

和mining_dev的区别是?


/// Auto-generate development keys for mining
#[arg(long = "mining.dev")]
pub mining_dev: bool,
Copy link
Owner Author

Choose a reason for hiding this comment

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

remove it. todo.

if let Some(ref pk_hex) = args.private_key {
mining_config.private_key_hex = Some(pk_hex.clone());
// Derive validator address from provided key
if let Ok(sk) = mining_config::keystore::load_private_key_from_hex(pk_hex) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

这步是什么意思?

/// Mining Service that handles block production for BSC
pub struct BscMiner<Pool, Provider> {
pool: Pool,
provider: Provider,
Copy link
Owner Author

Choose a reason for hiding this comment

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

这俩字段最重要. 重点关注.

return Err("No signing key configured".into());
};

// Derive validator address from the signing key and prefer it
Copy link
Owner Author

Choose a reason for hiding this comment

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

怎么理解这个含义?

}

// Ensure the genesis block header is cached so that the snapshot provider can create the genesis snapshot
{
Copy link
Owner Author

Choose a reason for hiding this comment

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

临时的mock,不该这样.


info!("Snapshot provider available, starting BSC mining service");

match BscMiner::new(
Copy link
Owner Author

Choose a reason for hiding this comment

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

嗯? 在这里??

Copy link
Owner Author

Choose a reason for hiding this comment

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

放在这里,整体上面感觉不太对头。 临时的,再think think.

@@ -0,0 +1,90 @@
// TODO: tmp mock, and will remove it later.
Copy link
Owner Author

Choose a reason for hiding this comment

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

mock. tmp

mining_config = mining_config.ensure_keys_available();

// Best-effort set; ignore error if already set
if let Err(_boxed_config) = mining_config::set_global_mining_config(mining_config) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

仅仅是set一个全局的配置?

+ 'static,
Evm: ConfigureEvm,
{
async fn spawn_payload_builder_service(
Copy link
Owner Author

Choose a reason for hiding this comment

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

看下eth的这个函数做了什么

self,
ctx: &BuilderContext<Node>,
_pool: Pool,
pool: Pool,
Copy link
Owner Author

Choose a reason for hiding this comment

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

_evm参数不该没用吧?

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.

3 participants