Skip to content

Commit 4688dd7

Browse files
committed
GetAnchors: return available anchors instead of failing
1 parent ab22a42 commit 4688dd7

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

chain/chainanchor.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
// returns anchor blocks of chain
2222
// use config
2323
func (cs *ChainService) getAnchorsNew() (ChainAnchor, types.BlockNo, error) {
24-
//from top : 8 * 32 = 256
24+
// from top : 32 (MaxAnchors) * 16 (Skip) = 512
2525
anchors := make(ChainAnchor, 0)
2626
cnt := MaxAnchors
2727
logger.Debug().Msg("get anchors")
@@ -32,7 +32,11 @@ LOOP:
3232
for i := 0; i < cnt; i++ {
3333
blockHash, err := cs.getHashByNo(blkNo)
3434
if err != nil {
35-
logger.Info().Msg("assertion - hash get failed")
35+
logger.Info().Uint64("blkno", blkNo).Msg("assertion - hash get failed")
36+
// if it got some anchors, return them
37+
if len(anchors) > 0 {
38+
break
39+
}
3640
// assertion!
3741
return nil, 0, err
3842
}
@@ -67,7 +71,11 @@ func (cs *ChainService) getAnchorsFromHash(blockHash []byte) ChainAnchor {
6771
for i := 0; i < 10; i++ {
6872
blockHash, err := cs.getHashByNo(latestNo)
6973
if err != nil {
70-
logger.Info().Msg("assertion - hash get failed")
74+
logger.Info().Uint64("blkno", latestNo).Msg("assertion - hash get failed")
75+
// if it got some anchors, return them
76+
if len(anchors) > 0 {
77+
break
78+
}
7179
// assertion!
7280
return nil
7381
}

chain/stubchain.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (tchain *StubBlockChain) GetHashByNo(blockNo types.BlockNo) ([]byte, error)
167167

168168
// TODO refactoring with getAnchorsNew()
169169
func (tchain *StubBlockChain) GetAnchors() (ChainAnchor, types.BlockNo, error) {
170-
//from top : 8 * 32 = 256
170+
// from top : 32 (MaxAnchors) * 16 (Skip) = 512
171171
anchors := make(ChainAnchor, 0)
172172
cnt := MaxAnchors
173173
logger.Debug().Msg("get anchors")
@@ -179,7 +179,11 @@ LOOP:
179179
for i := 0; i < cnt; i++ {
180180
blockHash, err := tchain.GetHashByNo(blkNo)
181181
if err != nil {
182-
logger.Info().Msg("assertion - hash get failed")
182+
logger.Info().Uint64("blkno", blkNo).Msg("assertion - hash get failed")
183+
// if it got some anchors, return them
184+
if len(anchors) > 0 {
185+
break
186+
}
183187
// assertion!
184188
return nil, 0, err
185189
}

0 commit comments

Comments
 (0)