-
Notifications
You must be signed in to change notification settings - Fork 283
SystemContract: support millisecond block generation #1174
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
base: develop
Are you sure you want to change the base?
Changes from 5 commits
2f9555e
2844e18
bad6a6c
b8d0863
e282204
1e378fa
1748594
d088aff
a7e3c17
446492a
ab1a331
d50ff4e
680221d
13a6df5
646679a
08f9a24
2e9d9f9
3abad55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -557,9 +557,24 @@ func (w *worker) newWork(now time.Time, parentHash common.Hash, reorging bool, r | |
// clique with relaxed period uses time.Now() as the header.Time, calculate the deadline | ||
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) | ||
if w.chainConfig.SystemContract != nil { | ||
periodMs := w.chainConfig.SystemContract.Period | ||
blocksPerSecond := uint64(1000) / periodMs | ||
if blocksPerSecond == 0 { | ||
blocksPerSecond = 1 | ||
} | ||
colinlyguo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 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) | ||
Comment on lines
+571
to
+572
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would happen if we didn't add one more period here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the deadline would be at the current time and thus the block would timeout immediately There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, true |
||
|
||
deadline = time.Unix(0, nextBlockNano) | ||
} | ||
|
||
w.current = &work{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.