From 1ad0a02932574c6dfdf7721ae877d0c8bee01b40 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 19 Aug 2022 09:37:53 +0200 Subject: [PATCH 1/3] consensus/beacon: check ttd reached on pos blocks --- consensus/beacon/consensus.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 0397b026f1f05..ef549ca0c26f8 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -116,6 +116,16 @@ func (beacon *Beacon) VerifyHeaders(chain consensus.ChainHeaderReader, headers [ // All the headers have passed the transition point, use new rules. if len(preHeaders) == 0 { + if reached, _ := IsTTDReached(chain, headers[0].ParentHash, headers[0].Number.Uint64()-1); !reached { + // TTD not reached for the first block, mark subsequent with invalid terminal block + results := make(chan error, len(headers)) + go func() { + for i := 0; i < len(headers); i++ { + results <- consensus.ErrInvalidTerminalBlock + } + }() + return make(chan struct{}), results + } return beacon.verifyHeaders(chain, headers, nil) } From 6d358428994863a060f22eede564aa34a4861e4f Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 19 Aug 2022 10:15:04 +0200 Subject: [PATCH 2/3] consensus/beacon: check ttd reached on pos blocks --- consensus/beacon/consensus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index ef549ca0c26f8..1a368932c670d 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -114,8 +114,8 @@ func (beacon *Beacon) VerifyHeaders(chain consensus.ChainHeaderReader, headers [ } } - // All the headers have passed the transition point, use new rules. if len(preHeaders) == 0 { + // All the headers are pos headers. Verify that the parent block reached total terminal difficulty. if reached, _ := IsTTDReached(chain, headers[0].ParentHash, headers[0].Number.Uint64()-1); !reached { // TTD not reached for the first block, mark subsequent with invalid terminal block results := make(chan error, len(headers)) From 7387e7e0b2b35040ec62ccd885b84a7c54a394cc Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 19 Aug 2022 10:35:36 +0200 Subject: [PATCH 3/3] consensus/beacon: check ttd reached on pos blocks --- consensus/beacon/consensus.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 1a368932c670d..949c8ad816ce5 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -119,11 +119,9 @@ func (beacon *Beacon) VerifyHeaders(chain consensus.ChainHeaderReader, headers [ if reached, _ := IsTTDReached(chain, headers[0].ParentHash, headers[0].Number.Uint64()-1); !reached { // TTD not reached for the first block, mark subsequent with invalid terminal block results := make(chan error, len(headers)) - go func() { - for i := 0; i < len(headers); i++ { - results <- consensus.ErrInvalidTerminalBlock - } - }() + for i := 0; i < len(headers); i++ { + results <- consensus.ErrInvalidTerminalBlock + } return make(chan struct{}), results } return beacon.verifyHeaders(chain, headers, nil)