From 1bb7e0df632f1e830d4495dea77c42e27aa9df44 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 30 Oct 2024 16:43:54 +0300 Subject: [PATCH 1/2] context: return preBlock from (*Context).PreBlock() From the user's PoW PreBlock should be returned from this method, not PreHeader, otherwise the behaviour is misleading and causes bugs. Signed-off-by: Anna Shaleva --- CHANGELOG.md | 1 + context.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c16a54a..db9dab2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Bugs fixed: * context-bound PreBlock and PreHeader are not reset properly (#127) * PreHeader is constructed instead of PreBlock to create PreCommit message (#128) * enable anti-MEV extension with respect to the current block index (#132) + * (*Context).PreBlock() method returns PreHeader instead of PreBlock (#133) ## [0.3.0] (01 August 2024) diff --git a/context.go b/context.go index 1a046cfe..b6c06333 100644 --- a/context.go +++ b/context.go @@ -214,8 +214,11 @@ func (c *Context[H]) MoreThanFNodesCommittedOrLost() bool { return c.CountCommitted()+c.CountFailed() > c.F() } +// PreBlock returns current PreBlock from context. May be nil in case if no +// PreBlock is constructed yet (even if PreHeader is already constructed). +// External changes in the PreBlock will be seen by dBFT. func (c *Context[H]) PreBlock() PreBlock[H] { - return c.preHeader // without transactions + return c.preBlock } func (c *Context[H]) reset(view byte, ts uint64) { From abb011fa7816ca66f0e06df2b46d5e2c8bb3a212 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 30 Oct 2024 16:46:34 +0300 Subject: [PATCH 2/2] *: move PreHeader() and Header() getters to Context These fields are a part of dBFT context, they should be accessible via those methods that expose Context to the user. Signed-off-by: Anna Shaleva --- CHANGELOG.md | 1 + context.go | 12 ++++++++++++ dbft.go | 12 ------------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db9dab2a..bc136bbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ New features: Behaviour changes: * adjust behaviour of ProcessPreBlock callback (#129) + * (*DBFT).Header() and (*DBFT).PreHeader() are moved to (*Context) receiver (#133) Improvements: * minimum required Go version is 1.22 (#122, #126) diff --git a/context.go b/context.go index b6c06333..4618c80f 100644 --- a/context.go +++ b/context.go @@ -214,6 +214,18 @@ func (c *Context[H]) MoreThanFNodesCommittedOrLost() bool { return c.CountCommitted()+c.CountFailed() > c.F() } +// Header returns current header from context. May be nil in case if no +// header is constructed yet. Do not change the resulting header. +func (c *Context[H]) Header() Block[H] { + return c.header +} + +// PreHeader returns current preHeader from context. May be nil in case if no +// preHeader is constructed yet. Do not change the resulting preHeader. +func (c *Context[H]) PreHeader() PreBlock[H] { + return c.preHeader +} + // PreBlock returns current PreBlock from context. May be nil in case if no // PreBlock is constructed yet (even if PreHeader is already constructed). // External changes in the PreBlock will be seen by dBFT. diff --git a/dbft.go b/dbft.go index fd34380f..26ae7261 100644 --- a/dbft.go +++ b/dbft.go @@ -703,15 +703,3 @@ func (d *DBFT[H]) extendTimer(count int) { d.Timer.Extend(time.Duration(count) * d.SecondsPerBlock / time.Duration(d.M())) } } - -// Header returns current header from context. May be nil in case if no -// header is constructed yet. Do not change the resulting header. -func (d *DBFT[H]) Header() Block[H] { - return d.header -} - -// PreHeader returns current preHeader from context. May be nil in case if no -// preHeader is constructed yet. Do not change the resulting preHeader. -func (d *DBFT[H]) PreHeader() PreBlock[H] { - return d.preHeader -}