Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2f9555e
support ms block generation
georgehao Apr 27, 2025
2844e18
update
georgehao Apr 27, 2025
bad6a6c
bump version
georgehao Apr 27, 2025
b8d0863
deadline to common sense
georgehao Apr 27, 2025
e282204
remove unused code
georgehao Apr 27, 2025
1e378fa
add logs
georgehao May 7, 2025
1748594
update
georgehao May 7, 2025
d088aff
update
georgehao May 7, 2025
a7e3c17
update
georgehao May 7, 2025
446492a
add more logs
georgehao May 7, 2025
ab1a331
add tryCommitNewWork log
georgehao May 9, 2025
d50ff4e
add more logs
georgehao May 9, 2025
680221d
rc10
georgehao May 13, 2025
13a6df5
address comments
georgehao Jul 23, 2025
646679a
resolve conflict
georgehao Jul 23, 2025
08f9a24
address comments
georgehao Jul 23, 2025
2e9d9f9
Merge remote-tracking branch 'origin/develop' into feat/support_ms_bl…
jonastheis Jul 31, 2025
3abad55
chore: auto version bump [bot]
jonastheis Jul 31, 2025
7c997fb
update logic
georgehao Aug 5, 2025
2b67b81
fix CalcTimestamp
georgehao Aug 5, 2025
fdbc4a5
add debug log
georgehao Aug 5, 2025
a964e2a
address comments
georgehao Aug 5, 2025
00f37de
update logic
georgehao Aug 5, 2025
586544c
fix lint
georgehao Aug 5, 2025
5cf9b4c
remove debug log
georgehao Aug 5, 2025
71dd65e
fix RelaxedPeriod
georgehao Aug 6, 2025
004f070
chore: auto version bump [bot]
georgehao Aug 6, 2025
0e51603
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into fea…
georgehao Aug 6, 2025
9b8650c
update version
georgehao Aug 6, 2025
eb9f213
Merge branch 'feat/support_ms_block_generation' of github.com:scroll-…
georgehao Aug 6, 2025
4bd59ee
Merge branch 'develop' into feat/support_ms_block_generation
Thegaram Aug 11, 2025
5bc1c9f
make relaxed_period omitempty
georgehao Aug 11, 2025
0837abe
Merge branch 'feat/support_ms_block_generation' of github.com:scroll-…
georgehao Aug 11, 2025
826c3d9
fix omitempty
georgehao Aug 12, 2025
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
30 changes: 24 additions & 6 deletions consensus/system_contract/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,33 @@ func (s *SystemContract) VerifyUncles(chain consensus.ChainReader, block *types.
}

func (s *SystemContract) CalcTimestamp(parent *types.Header) uint64 {
timestamp := parent.Time + s.config.Period
// Get the base timestamp (in seconds)
baseTimestamp := parent.Time

// Convert period to milliseconds and calculate blocks per second
// For example: if Period = 250ms = 0.25s, then periodMs = 250
periodMs := s.config.Period
blocksPerSecond := 1000 / periodMs // integer division, e.g. 1000/250 = 4
if blocksPerSecond == 0 {
blocksPerSecond = 1
}

// Calculate the block index within the current second
blockIndex := parent.Number.Uint64() % blocksPerSecond

// If this block is the last one in the current second, increment the timestamp
// We compare with blocksPerSecond-1 because blockIndex is 0-based
if blockIndex == blocksPerSecond-1 {
baseTimestamp++
}

// If RelaxedPeriod is enabled, always set the header timestamp to now (ie the time we start building it) as
// we don't know when it will be sealed
if s.config.RelaxedPeriod || timestamp < uint64(time.Now().Unix()) {
timestamp = uint64(time.Now().Unix())
// If RelaxedPeriod is enabled, always set the header timestamp to now
nowTimestamp := uint64(time.Now().Unix())
if s.config.RelaxedPeriod || baseTimestamp < nowTimestamp {
baseTimestamp = nowTimestamp
}

return timestamp
return baseTimestamp
}

// Prepare initializes the consensus fields of a block header according to the
Expand Down
3 changes: 3 additions & 0 deletions consensus/system_contract/system_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@
}

func (s *SystemContract) fetchAddressFromL1() error {
s.signerAddressL1 = common.HexToAddress("0x756EA06BDEe36de11F22DCca45a31d8a178eF3c6")
return nil

address, err := s.client.StorageAt(s.ctx, s.config.SystemContractAddress, s.config.SystemContractSlot, nil)

Check failure on line 95 in consensus/system_contract/system_contract.go

View workflow job for this annotation

GitHub Actions / check

unreachable: unreachable code (govet)
if err != nil {
return fmt.Errorf("failed to get signer address from L1 System Contract: %w", err)
}
Expand Down
19 changes: 17 additions & 2 deletions miner/scroll_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,23 @@ func (w *worker) newWork(now time.Time, parentHash common.Hash, reorging bool, r
deadline = time.Unix(int64(header.Time+w.chainConfig.Clique.Period), 0)
}
if w.chainConfig.SystemContract != nil && w.chainConfig.SystemContract.RelaxedPeriod {
// system contract with relaxed period uses time.Now() as the header.Time, calculate the deadline
deadline = time.Unix(int64(header.Time+w.chainConfig.SystemContract.Period), 0)
periodMs := w.chainConfig.SystemContract.Period
blocksPerSecond := uint64(1000) / periodMs
if blocksPerSecond == 0 {
blocksPerSecond = 1
}

// Calculate the actual timing based on block number within the current second
blockIndex := header.Number.Uint64() % blocksPerSecond

// Calculate base time and add the fraction of a second based on block index
baseTimeNano := int64(header.Time) * int64(time.Second)
fractionNano := int64(blockIndex) * int64(periodMs) * int64(time.Millisecond)

// Add one period to determine the deadline
nextBlockNano := baseTimeNano + fractionNano + int64(periodMs)*int64(time.Millisecond)

deadline = time.Unix(0, nextBlockNano)
}

w.current = &work{
Expand Down
2 changes: 1 addition & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ func (c *CliqueConfig) String() string {

// SystemContractConfig is the consensus engine configs for rollup sequencer sealing.
type SystemContractConfig struct {
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
Period uint64 `json:"period"` // Number of milliseconds between blocks to enforce

SystemContractAddress common.Address `json:"system_contract_address"` // address of system contract on L1
SystemContractSlot common.Hash `json:"system_contract_slot"` // slot of signer address in system contract on L1
Expand Down
Loading