Refactor window iteration into entry
This commit is contained in:
parent
74ff0d870f
commit
17ff7124df
8
bot.go
8
bot.go
|
@ -317,7 +317,7 @@ func main() {
|
|||
var yourWeight types.Difficulty
|
||||
var totalWeight types.Difficulty
|
||||
|
||||
for range index.IterateSideBlocksInPPLNSWindow(tip, e.Consensus, e.DifficultyFromHeight, e.SideBlockByTemplateId, e.SideBlockUnclesByTemplateId, func(b *index.SideBlock, weight types.Difficulty) {
|
||||
e.IterateWindow(func(b *index.SideBlock, weight types.Difficulty) {
|
||||
totalWeight = totalWeight.Add(weight)
|
||||
if tip.Miner == b.Miner {
|
||||
if b.IsUncle() {
|
||||
|
@ -327,11 +327,7 @@ func main() {
|
|||
}
|
||||
yourWeight = yourWeight.Add(weight)
|
||||
}
|
||||
}, func(err error) {
|
||||
|
||||
}) {
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
shareRatio := float64(yourWeight.Lo) / float64(totalWeight.Lo)
|
||||
if shareRatio > notificationPoolShare { //disable spammy notifications
|
||||
|
|
16
commands.go
16
commands.go
|
@ -71,7 +71,7 @@ var commands = []command{
|
|||
tr = append(tr, &r)
|
||||
}
|
||||
|
||||
for range index.IterateSideBlocksInPPLNSWindow(e.Tip, e.Consensus, e.DifficultyFromHeight, e.SideBlockByTemplateId, e.SideBlockUnclesByTemplateId, func(b *index.SideBlock, weight types.Difficulty) {
|
||||
e.IterateWindow(func(b *index.SideBlock, weight types.Difficulty) {
|
||||
for _, r := range tr {
|
||||
r.TotalWeight = r.TotalWeight.Add(weight)
|
||||
if b.MinerAddress.Compare(r.Address) == 0 {
|
||||
|
@ -86,11 +86,7 @@ var commands = []command{
|
|||
}
|
||||
}
|
||||
}
|
||||
}, func(err error) {
|
||||
|
||||
}) {
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
for _, r := range tr {
|
||||
if r.ShareCount > 0 || r.UncleCount > 0 {
|
||||
|
@ -153,16 +149,12 @@ var commands = []command{
|
|||
var yourWeight types.Difficulty
|
||||
var totalWeight types.Difficulty
|
||||
|
||||
for range index.IterateSideBlocksInPPLNSWindow(e.Tip, e.Consensus, e.DifficultyFromHeight, e.SideBlockByTemplateId, e.SideBlockUnclesByTemplateId, func(b *index.SideBlock, weight types.Difficulty) {
|
||||
e.IterateWindow(func(b *index.SideBlock, weight types.Difficulty) {
|
||||
totalWeight = totalWeight.Add(weight)
|
||||
if b.MinerAddress.Compare(addr) == 0 {
|
||||
yourWeight = yourWeight.Add(weight)
|
||||
}
|
||||
}, func(err error) {
|
||||
|
||||
}) {
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
shareRatio := float64(yourWeight.Lo) / float64(totalWeight.Lo)
|
||||
if shareRatio > notificationPoolShare { //warn about spammy notifications
|
||||
|
|
14
entry.go
14
entry.go
|
@ -58,6 +58,20 @@ func (c *channelEntry) SideBlockUnclesByTemplateId(id types.Hash) chan *index.Si
|
|||
return result
|
||||
}
|
||||
|
||||
// IterateWindow lock must be taken before this
|
||||
func (c *channelEntry) IterateWindow(addWeightFunc index.SideBlockWindowAddWeightFunc) (bottomHeight uint64) {
|
||||
if c.ApiEndpoint == "" {
|
||||
return
|
||||
}
|
||||
|
||||
for e := range index.IterateSideBlocksInPPLNSWindow(c.Tip, c.Consensus, c.DifficultyFromHeight, c.SideBlockByTemplateId, c.SideBlockUnclesByTemplateId, addWeightFunc, func(err error) {
|
||||
|
||||
}) {
|
||||
bottomHeight = e.Block.SideHeight
|
||||
}
|
||||
return bottomHeight
|
||||
}
|
||||
|
||||
func (c *channelEntry) SideBlockByTemplateId(id types.Hash) *index.SideBlock {
|
||||
if b, ok := c.Window[id]; ok {
|
||||
return b
|
||||
|
|
Loading…
Reference in a new issue