Skip to content

Commit

Permalink
Regression corrected.
Browse files Browse the repository at this point in the history
duniter/sandbox: 'idHashT' may be nil when entering 'pruneMembershipIds' & 'membershipIds', 'certFromT' (& 'certToT') may be nil when entering 'pruneCertifications' & 'certifications'.
  • Loading branch information
gerard94 committed Sep 25, 2021
1 parent ad00b58 commit 8a1d9a5
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/duniter/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (

const (

version = "5.4.0"
version = "5.4.1"

)

Expand Down
130 changes: 70 additions & 60 deletions src/duniter/sandbox/sandbox.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
WotWizard
Copyright (C) 2017-2020 GérardMeunier
Expand Down Expand Up @@ -416,29 +416,31 @@ func extractBlockId (buid string) Hash {

// Remove no more valid membership applications in 'idHashT', because they expired, or identities are now in blockchain as members or revoked, or their uids ot pubkeys are already in blockchain
func pruneMembershipIds () {
now := B.Now()
e := idHashT.Next(nil)
for e != nil {
ee := idHashT.Next(e)
idH := e.Val().(*idHashE)
old := now >= idH.expires_on
if !old {
pub, inBC := B.IdHash(idH.hash)
if inBC {
_, member, _, _, _, limitDate, b := B.IdPubComplete(pub); M.Assert(b, 100)
old = member || limitDate == BA.Revoked
if idHashT != nil {
now := B.Now()
e := idHashT.Next(nil)
for e != nil {
ee := idHashT.Next(e)
idH := e.Val().(*idHashE)
old := now >= idH.expires_on
if !old {
pub, inBC := B.IdHash(idH.hash)
if inBC {
_, member, _, _, _, limitDate, b := B.IdPubComplete(pub); M.Assert(b, 100)
old = member || limitDate == BA.Revoked
}
}
if !old {
_, old = B.IdPub(idH.pubkey)
}
if !old {
_, old = B.IdUid(idH.uid)
}
if old {
b := idHashT.Delete(idH); M.Assert(b, 101)
}
e = ee
}
if !old {
_, old = B.IdPub(idH.pubkey)
}
if !old {
_, old = B.IdUid(idH.uid)
}
if old {
b := idHashT.Delete(idH); M.Assert(b, 101)
}
e = ee
}
} //pruneMembershipIds

Expand Down Expand Up @@ -473,6 +475,9 @@ func membershipIds (d *Q.DB) {
tr.Delete(idH)
}
}
if idHashT == nil {
idHashT = A.New()
}
e := tr.Next(nil)
for e != nil { // For every membership applications
idH := e.Val().(*idHashE)
Expand Down Expand Up @@ -528,49 +533,51 @@ func membershipIds (d *Q.DB) {

// Remove no more valid certifications in 'certFromT' and 'certToT', because they expired, or they are in blockchain and were written in blockchain after they were written in sandbox, or their receivers are no more in sandbox nor in blockchain, or their senders are no more members
func pruneCertifications () {
now := B.Now()
e := certFromT.Next(nil)
for e != nil {
ee := certFromT.Next(e)
cF := e.Val().(*certFromE)
cTT := cF.list
f := cTT.Next(nil)
for f != nil {
ff := cTT.Next(f)
cT := f.Val().(*certToE)
c := cT.certification
old := now >= c.expires_on
if !old {
bnbBC, _, inBC := B.Cert(c.from, c.to)
old = inBC && bnbBC >= c.bnb
}
if !old {
old = idHashId(c.toHash) == nil
if old {
_, inBC := B.IdPub(c.to)
old = !inBC
if certFromT != nil {
now := B.Now()
e := certFromT.Next(nil)
for e != nil {
ee := certFromT.Next(e)
cF := e.Val().(*certFromE)
cTT := cF.list
f := cTT.Next(nil)
for f != nil {
ff := cTT.Next(f)
cT := f.Val().(*certToE)
c := cT.certification
old := now >= c.expires_on
if !old {
bnbBC, _, inBC := B.Cert(c.from, c.to)
old = inBC && bnbBC >= c.bnb
}
}
if !old {
_, member, _, _, _, _, inBC := B.IdPubComplete(c.from); M.Assert(inBC, 100)
old = !member
}
if old {
b := cTT.Delete(cT); M.Assert(b, 100)
if cTT.NumberOfElems() == 0 {
b = certFromT.Delete(cF); M.Assert(b, 101)
if !old {
old = idHashId(c.toHash) == nil
if old {
_, inBC := B.IdPub(c.to)
old = !inBC
}
}
g, b, _ := certToT.Search(&certToE{certification: c}); M.Assert(b, 102)
cT := g.Val().(*certToE)
cFT := cT.list
b = cFT.Delete(&certFromE{certification: c}); M.Assert(b, 103)
if cFT.NumberOfElems() == 0 {
b = certToT.Delete(cT); M.Assert(b, 104)
if !old {
_, member, _, _, _, _, inBC := B.IdPubComplete(c.from); M.Assert(inBC, 100)
old = !member
}
if old {
b := cTT.Delete(cT); M.Assert(b, 100)
if cTT.NumberOfElems() == 0 {
b = certFromT.Delete(cF); M.Assert(b, 101)
}
g, b, _ := certToT.Search(&certToE{certification: c}); M.Assert(b, 102)
cT := g.Val().(*certToE)
cFT := cT.list
b = cFT.Delete(&certFromE{certification: c}); M.Assert(b, 103)
if cFT.NumberOfElems() == 0 {
b = certToT.Delete(cT); M.Assert(b, 104)
}
}
f = ff
}
f = ff
e = ee
}
e = ee
}
} //pruneCertifications

Expand All @@ -579,6 +586,9 @@ func certifications (d *Q.DB) {
rows, err := d.Query("SELECT [from], [to], target, block_number, expires_on FROM cert INNER JOIN block ON cert.block_hash = block.hash WHERE NOT block.fork")
M.Assert(err == nil, err, 100)
now := B.Now()
if certFromT == nil {
certFromT = A.New(); certToT = A.New()
}
for rows.Next() {
var (
f,
Expand Down

0 comments on commit 8a1d9a5

Please sign in to comment.