Skip to content
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

FD-1084 : A synced node keeps requesting dbstates even after it is synced #780

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions common/constants/ack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

package constants

const (
// MaxAckHeightMinuteDelta is the maximum number of minute in the
// future we will set our HighestAckHeight too. This means
// 2000/10 = max number of blocks to set the max height too ontop
// of our current block height.
MaxAckHeightMinuteDelta = 2000
)

// Ack status levels
const (
_ int = iota
Expand Down
4 changes: 2 additions & 2 deletions common/messages/ack.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (m *Ack) Validate(s interfaces.IState) int {
// Update the highest known ack to start requesting
// DBState blocks if necessary
if s.GetHighestAck() < m.DBHeight {
if delta > 2000 { // cap at a relative 2000 due to fd-850
s.SetHighestAck(s.GetLeaderPL().GetDBHeight() + 2000)
if delta > constants.MaxAckHeightMinuteDelta { // cap at a relative 200 blks due to fd-850
s.SetHighestAck(s.GetLeaderPL().GetDBHeight() + constants.MaxAckHeightMinuteDelta/10)
} else {
s.SetHighestAck(m.DBHeight)
}
Expand Down
17 changes: 11 additions & 6 deletions state/dbStateCatchup.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (list *DBStateList) Catchup() {
// if it is not received and not already requested.
notifyMissing := func(n uint32) bool {
if !waiting.Has(n) {
list.State.LogPrintf("dbstatecatchup", "{actual} notify missing %d", n)
missing.Add(n)
return true
}
Expand Down Expand Up @@ -153,7 +154,7 @@ func (list *DBStateList) Catchup() {
// TODO: that might be made
max := 3000 // Limit the number of new asks we will add for each iteration
// add all known states after the last received to the missing list
for n := received.Heighestreceived() + 1; n < hk && max > 0; n++ {
for n := received.Heighestreceived() + 1; n <= hk && max > 0; n++ {
max--
// missing.Notify <- NewMissingState(n)
r := notifyMissing(n)
Expand All @@ -179,7 +180,7 @@ func (list *DBStateList) Catchup() {
//for e := waiting.List.Front(); e != nil; e = e.Next() {
for _, s := range waitingSlice {
// Instead of choosing if to ask for it, just remove it
if s.Height() < base {
if s.Height() <= base {
waiting.LockAndDelete(s.Height())
continue
}
Expand Down Expand Up @@ -218,6 +219,7 @@ func (list *DBStateList) Catchup() {
if waiting.Len() < requestLimit {
// TODO: the batch limit should probably be set by a configuration variable
b, e := missing.NextConsecutiveMissing(10)
list.State.LogPrintf("dbstatecatchup", "dbstate requesting from %d to %d", b, e)

if b == 0 && e == 0 {
time.Sleep(1 * time.Second)
Expand All @@ -231,9 +233,9 @@ func (list *DBStateList) Catchup() {

msg := messages.NewDBStateMissing(list.State, b, e)
msg.SendOut(list.State, msg)
list.State.DBStateAskCnt += int(e-b) + 1 // Total number of dbstates requested
list.State.DBStateAskCnt += 1 // Total number of dbstates requests
for i := b; i <= e; i++ {
list.State.LogPrintf("dbstatecatchup", "dbstate requested : missing -> waiting %d", i)
list.State.LogPrintf("dbstatecatchup", "\tdbstate requested : missing -> waiting %d", i)
missing.LockAndDelete(i)
waiting.Add(i)
}
Expand Down Expand Up @@ -376,9 +378,12 @@ func (l *StatesMissing) NextConsecutiveMissing(n int) (uint32, uint32) {
beg := f.Value.(*MissingState).Height()
end := beg
c := 0
for e := l.List.Front(); e != nil; e = e.Next() {
for e := f.Next(); e != nil; e = e.Next() {
h := e.Value.(*MissingState).Height()
if h > end+1 {
// We are looking to see if the consecutive height
// sequence is broken. Easy to check if h != the next one
// we are expecting.
if h != end+1 {
break
}
end++
Expand Down
24 changes: 24 additions & 0 deletions state/dbStateCatchup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,27 @@ func testDBStateListAdditionsMissing(list GenericList, t *testing.T, testname st
// t.Errorf("Exp len of 0, found %d", list.Len())
//}
}

func TestMissingConsecutive(t *testing.T) {
testMissingConsecutive(t, []int{10, 11, 12, 13, 20}, 10, 10, 13)
testMissingConsecutive(t, []int{10, 11, 12, 13}, 10, 10, 13)
testMissingConsecutive(t, []int{10, 11, 12, 13, 15, 20}, 10, 10, 13)
testMissingConsecutive(t, []int{10, 11, 12, 13, 15, 20}, 2, 10, 12)
testMissingConsecutive(t, []int{1, 10, 11, 12, 13, 15, 20}, 10, 1, 1)
testMissingConsecutive(t, []int{10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}, 10, 10, 20)
testMissingConsecutive(t, []int{}, 10, 0, 0)
testMissingConsecutive(t, []int{1, 2}, 10, 1, 2)

}

func testMissingConsecutive(t *testing.T, add []int, n, bExp, eExp int) {
m := state.NewStatesMissing()
for _, a := range add {
m.Add(uint32(a))
}

b, e := m.NextConsecutiveMissing(n)
if b != uint32(bExp) || e != uint32(eExp) {
t.Errorf("Expected %d-%d, found %d-%d", bExp, eExp, b, e)
}
}