@@ -2055,6 +2055,7 @@ func getLongAndShortChains() (bc *BlockChain, longChain []*types.Block, heavyCha
2055
2055
// 1. Have a chain [0 ... N .. X]
2056
2056
// 2. Reorg to shorter but heavier chain [0 ... N ... Y]
2057
2057
// 3. Then there should be no canon mapping for the block at height X
2058
+ // 4. The forked block should still be retrievable by hash
2058
2059
func TestReorgToShorterRemovesCanonMapping (t * testing.T ) {
2059
2060
chain , canonblocks , sideblocks , err := getLongAndShortChains ()
2060
2061
if err != nil {
@@ -2064,6 +2065,7 @@ func TestReorgToShorterRemovesCanonMapping(t *testing.T) {
2064
2065
t .Fatalf ("block %d: failed to insert into chain: %v" , n , err )
2065
2066
}
2066
2067
canonNum := chain .CurrentBlock ().NumberU64 ()
2068
+ canonHash := chain .CurrentBlock ().Hash ()
2067
2069
_ , err = chain .InsertChain (sideblocks )
2068
2070
if err != nil {
2069
2071
t .Errorf ("Got error, %v" , err )
@@ -2079,6 +2081,12 @@ func TestReorgToShorterRemovesCanonMapping(t *testing.T) {
2079
2081
if headerByNum := chain .GetHeaderByNumber (canonNum ); headerByNum != nil {
2080
2082
t .Errorf ("expected header to be gone: %v" , headerByNum .Number .Uint64 ())
2081
2083
}
2084
+ if blockByHash := chain .GetBlockByHash (canonHash ); blockByHash == nil {
2085
+ t .Errorf ("expected block to be present: %x" , blockByHash .Hash ())
2086
+ }
2087
+ if headerByHash := chain .GetHeaderByHash (canonHash ); headerByHash == nil {
2088
+ t .Errorf ("expected header to be present: %x" , headerByHash .Hash ())
2089
+ }
2082
2090
}
2083
2091
2084
2092
// TestReorgToShorterRemovesCanonMappingHeaderChain is the same scenario
@@ -2098,6 +2106,7 @@ func TestReorgToShorterRemovesCanonMappingHeaderChain(t *testing.T) {
2098
2106
t .Fatalf ("header %d: failed to insert into chain: %v" , n , err )
2099
2107
}
2100
2108
canonNum := chain .CurrentHeader ().Number .Uint64 ()
2109
+ canonHash := chain .CurrentBlock ().Hash ()
2101
2110
sideHeaders := make ([]* types.Header , len (sideblocks ))
2102
2111
for i , block := range sideblocks {
2103
2112
sideHeaders [i ] = block .Header ()
@@ -2116,6 +2125,12 @@ func TestReorgToShorterRemovesCanonMappingHeaderChain(t *testing.T) {
2116
2125
if headerByNum := chain .GetHeaderByNumber (canonNum ); headerByNum != nil {
2117
2126
t .Errorf ("expected header to be gone: %v" , headerByNum .Number .Uint64 ())
2118
2127
}
2128
+ if blockByHash := chain .GetBlockByHash (canonHash ); blockByHash == nil {
2129
+ t .Errorf ("expected block to be present: %x" , blockByHash .Hash ())
2130
+ }
2131
+ if headerByHash := chain .GetHeaderByHash (canonHash ); headerByHash == nil {
2132
+ t .Errorf ("expected header to be present: %x" , headerByHash .Hash ())
2133
+ }
2119
2134
}
2120
2135
2121
2136
func TestTransactionIndices (t * testing.T ) {
0 commit comments