Skip to content

Commit

Permalink
duniter/sandbox: Do no more build sandbox data (in 'idHashT', 'certFr…
Browse files Browse the repository at this point in the history
…omT' and 'certToT') from scratch, but update them; legacy data are removed in functions 'pruneMembershipIds' for 'idHashT' and 'pruneCertifications' for 'certFromT' and 'certToT'.

duniterClient/identitySearch & duniterClient/static/vars.go: Enhancement of displays.
  • Loading branch information
gerard94 committed Sep 21, 2021
1 parent 9db846c commit ad00b58
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 29 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.3.4"
version = "5.4.0"

)

Expand Down
86 changes: 81 additions & 5 deletions src/duniter/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type (
list *A.Tree
}

certToE struct { // Sorted by to
certToE struct { // Sorted by toHash
*certification
list *A.Tree
}
Expand Down Expand Up @@ -414,6 +414,34 @@ func extractBlockId (buid string) Hash {
return Hash(string(b[i + 1:]))
} //extractBlockId

// 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 !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

// Scan the membership and the idty tables in the Duniter database and build idHashT, idPubT and idUidT; remove all items which reference a forked block
func membershipIds (d *Q.DB) {
// Membership applications
Expand Down Expand Up @@ -445,15 +473,14 @@ func membershipIds (d *Q.DB) {
tr.Delete(idH)
}
}
idHashT = A.New()
e := tr.Next(nil)
for e != nil { // For every membership applications
idH := e.Val().(*idHashE)
if p, ok := B.IdHash(idH.hash); ok { // If identity already in BC...
if uid, b, _, _, _, exp, ok := B.IdPubComplete(p); ok && !b && exp != BA.Revoked { // ... and if no more member but not revoked
M.Assert(uid == idH.uid, 112)
id := &identity{inBC: true, hash: idH.hash, pubkey: p, uid: uid, bnb: idH.bnb, expires_on: M.Min64(M.Abs64(exp), idH.expires_on)}
_, b, _ = idHashT.SearchIns(&idHashE{identity: id}); M.Assert(!b, 104)
idHashT.SearchIns(&idHashE{identity: id})
}
} else {
_, ok := B.IdPub(idH.pubkey)
Expand Down Expand Up @@ -481,7 +508,7 @@ func membershipIds (d *Q.DB) {
if !r {
M.Assert(Pubkey(pubkey) == idH.pubkey && uid == idH.uid, 113)
id := &identity{inBC: false, hash: idH.hash, pubkey: Pubkey(pubkey), uid: uid, bnb: idH.bnb, expires_on: M.Min64(idH.expires_on, expires_on)}
_, b, _ := idHashT.SearchIns(&idHashE{identity: id}); M.Assert(!b, 109)
idHashT.SearchIns(&idHashE{identity: id})
}
}
}
Expand All @@ -499,12 +526,59 @@ func membershipIds (d *Q.DB) {
}
} //membershipIds

// 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 !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
}
e = ee
}
} //pruneCertifications

// Builds certFromT and certToT from the Duniter database; remove all certifications where block_hash is in a fork
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()
certFromT = A.New(); certToT = A.New()
for rows.Next() {
var (
f,
Expand Down Expand Up @@ -636,7 +710,9 @@ func scan (... interface{}) {
d, err := Q.Open(B.Driver(), BA.DuniBase)
M.Assert(err == nil, err, 100)
defer d.Close()
pruneMembershipIds()
membershipIds(d)
pruneCertifications()
certifications(d)
export()
BA.Lg.Println("Sandbox updated")
Expand Down
39 changes: 19 additions & 20 deletions src/duniterClient/identitySearch/identitySearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const (
{{.Hash}}
</p>
<p>
{{.Member}}
{{.Status}}
</p>
{{if .Sentry}}
<p>
Expand Down Expand Up @@ -254,9 +254,11 @@ const (
{{.Block}}
</p>
{{end}}
<p>
{{.LimitDate}}
</p>
{{if .LimitDate}}
<p>
{{.LimitDate}}
</p>
{{end}}
{{if .Availability}}
<p>
{{.Availability}}
Expand Down Expand Up @@ -583,7 +585,7 @@ type (
Uid,
Pubkey,
Hash,
Member,
Status,
Sentry,
Block,
LimitDate,
Expand Down Expand Up @@ -728,9 +730,9 @@ func certs (res *Identity, lang *SM.Lang) *Certifics {
es.exps = make(ListI, len(sentCerts))
for i, c := range certifs {
if c.Pending {
sentCerts[i] = string(newcomerIcon) + " " + c.To.Uid
sentCerts[i] = string(newcomerIcon) + " " + c.To.Uid + BA.SpS
} else {
sentCerts[i] = c.To.Uid
sentCerts[i] = c.To.Uid + BA.SpS
}
es.exps[i] = c.Expires_on
}
Expand All @@ -744,7 +746,7 @@ func certs (res *Identity, lang *SM.Lang) *Certifics {
allCertified = lang.Map("#duniterClient:AllCertified")
sentAllCerts = make(ListS, len(res.All_certified))
for i, a := range res.All_certified {
sentAllCerts[i] = a.Uid
sentAllCerts[i] = a.Uid + BA.SpS
}
allCertifiedIO = lang.Map("#duniterClient:AllCertifiedIO")
sentAllCertsIO = make(ListCH, len(res.All_certifiedIO))
Expand Down Expand Up @@ -773,9 +775,9 @@ func certs (res *Identity, lang *SM.Lang) *Certifics {
es.exps = make(ListI, len(receivedCerts))
for i, c := range certifs {
if c.Pending {
receivedCerts[i] = string(newcomerIcon) + " " + c.From.Uid
receivedCerts[i] = string(newcomerIcon) + " " + c.From.Uid + BA.SpS
} else {
receivedCerts[i] = c.From.Uid
receivedCerts[i] = c.From.Uid + BA.SpS
}
es.exps[i] = c.Expires_on
}
Expand All @@ -796,7 +798,7 @@ func certs (res *Identity, lang *SM.Lang) *Certifics {
allCertifiers = lang.Map("#duniterClient:AllCertifiers")
receivedAllCerts = make(ListS, len(res.All_certifiers))
for i, a := range res.All_certifiers {
receivedAllCerts[i] = a.Uid
receivedAllCerts[i] = a.Uid + BA.SpS
}
allCertifiersIO = lang.Map("#duniterClient:AllCertifiersIO")
receivedAllCertsIO = make(ListCH, len(res.All_certifiersIO))
Expand Down Expand Up @@ -848,11 +850,10 @@ func get (res *Identity, lang *SM.Lang) *Idty {
uid := fmt.Sprint(lang.Map("#duniterClient:Nickname"), BA.SpL, res.Uid)
hash := fmt.Sprint(lang.Map("#duniterClient:Hash"), BA.SpL, string(res.Hash))
pubkey := fmt.Sprint(lang.Map("#duniterClient:Pubkey"), BA.SpL, string(res.Pubkey))
member := fmt.Sprint(lang.Map("#duniterClient:Member"), BA.SpL)
status := fmt.Sprint(lang.Map("#duniterClient:Status"), BA.SpL, lang.Map("#duniterClient:" + res.Status))
sentry := ""
availability := ""
if res.Status == "MEMBER" {
member += yes
sentry = fmt.Sprint(lang.Map("#duniterClient:Sentry"), BA.SpL)
if res.Sentry {
sentry += yes
Expand All @@ -870,8 +871,6 @@ func get (res *Identity, lang *SM.Lang) *Idty {
if availability != "" {
availability = fmt.Sprint(lang.Map("#duniterClient:Availability"), BA.SpL, availability)
}
} else {
member += no
}
var block string
if res.Id_written_block == nil {
Expand All @@ -882,7 +881,7 @@ func get (res *Identity, lang *SM.Lang) *Idty {
var limitDate string
switch res.Status {
case "REVOKED":
limitDate = BA.Ts2s(BA.Revoked, lang)
limitDate = ""
case "MISSING":
limitDate = fmt.Sprint(lang.Map("#duniterClient:AppRLimitDate"), BA.SpL, BA.Ts2s(res.LimitDate, lang))
case "MEMBER":
Expand All @@ -900,11 +899,11 @@ func get (res *Identity, lang *SM.Lang) *Idty {
pending = ""
}
history := printHistory(res.History, lang)
return &Idty{uid, pubkey, hash, member, sentry, block, limitDate, availability, pending, history}
return &Idty{uid, pubkey, hash, status, sentry, block, limitDate, availability, pending, history}
} //get

func notTooFar (res *Identity, lang *SM.Lang) string {
if res.Distance == nil {
if res.Status == "REVOKED" || res.Distance == nil {
return ""
}
d := res.Distance
Expand All @@ -919,14 +918,14 @@ func notTooFar (res *Identity, lang *SM.Lang) string {
} //notTooFar

func calcQuality (res *Identity, lang *SM.Lang) string {
if res.Quality == 0 {
if res.Status == "REVOKED" || res.Quality == 0 {
return ""
}
return fmt.Sprint(lang.Map("#duniterClient:Quality"), BA.SpL, strconv.FormatFloat(res.Quality, 'f', 2, 64), "%")
} //calcQuality

func calcCentrality (res *Identity, lang *SM.Lang) string {
if res.Centrality == 0 {
if res.Status == "REVOKED" || res.Centrality == 0 {
return ""
}
return fmt.Sprint(lang.Map("#duniterClient:Centrality"), BA.SpL, strconv.FormatFloat(res.Centrality, 'f', 2, 64), "%")
Expand Down
2 changes: 1 addition & 1 deletion src/duniterClient/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (

const (

version = "5.3.5"
version = "5.4.0"

)

Expand Down
12 changes: 10 additions & 2 deletions src/duniterClient/static/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ LossesFlux Flux of Losses
LossesFluxPM Flux of Losses per Member
Mean Mean
Median Median
Member Member
MEMBER MEMBER
53memberIdentities Informations: Members List
Members Members
404membersCountFlux Evolution: Flux of Members (graphics)
Expand All @@ -109,12 +109,14 @@ MembersNb Number of members
33memLim Limits: Memberships Limits Date by Date
minApplicationDate Wait at least two months after the last application (^0)
minute minute(s)
MISSING MISSING
Missing Excluded Identities - Needing a new application
52missingIdentities Informations: List of Excluded Identities - Needing a new application
MissingNb Number of Excluded Identities
Missings Excluded
month month
Never Never
NEWCOMER NEWCOMER
54newcomerIdentities Informations: List of Newcomers
Newcomers Newcomers
newcomers Pending Dossiers
Expand All @@ -137,6 +139,7 @@ Pubkey Public Key
qualities Qualities
Quality Quality
requiredCertsNb ^0 certifications, ^1 needed for distance rule
REVOKED REVOKED
Revoked Revoked
51revokedIdentities Informations: List of Revoked Identities
RevokedM Revoked Identities
Expand All @@ -155,6 +158,7 @@ Server Server Version:
ShowFile Dossier
SortedByCExpDates Sorted by Expiration Dates of Certifications
SortedByCExpDatesL Sorted by Expiration Dates of Certifications (→: limit date)
Status Status
Threshold Threshold
TypeUidOrPubkey Start of Nickname or Public Key
Utc Blockchain Actual Time
Expand Down Expand Up @@ -241,7 +245,7 @@ LossesFlux Flux de pertes
LossesFluxPM Flux de pertes par membre
Mean Moyenne
Median Médiane
Member Membre
MEMBER MEMBRE
53memberIdentities Informations : Liste des membres
Members Membres
404membersCountFlux Evolution : Flux de membres (graphique)
Expand All @@ -262,12 +266,14 @@ MembersNb Nombre de membres
33memLim Limites : Limites des adhésions par date
minApplicationDate Au moins deux mois d'attente après la dernière adhésion (^0)
minute minute(s)
MISSING EXCLU(E)
Missing Exclu(e)s en attente de réadhésion
52missingIdentities Informations : Liste des identités exclues en attente de réadhésion
MissingNb Nombre des exclu(e)s
Missings Exclu(e)s
month mois
Never Jamais
NEWCOMER ARRIVANT(E)
54newcomerIdentities Informations : Liste des arrivant(e)s
Newcomers Arrivant(e)s
newcomers dossiers en attente
Expand All @@ -290,6 +296,7 @@ Pubkey Clef publique
qualities Qualités
Quality Qualité
requiredCertsNb ^0 certifications, ^1 nécessaires pour la règle de distance
REVOKED RÉVOQUÉ(E)
Revoked Révoqué(e)
51revokedIdentities Informations : Liste des identités révoquées
RevokedM Identités révoquées
Expand All @@ -308,6 +315,7 @@ Server Version serveur :
ShowFile Fichier
SortedByCExpDates Tri par dates d'expiration des certifications
SortedByCExpDatesL Tri par dates d'expiration des certifications (→ : date limite)
Status Statut
Threshold Seuil
TypeUidOrPubkey Début de pseudo ou de clef publique
Utc Temps réel de la chaîne de blocs
Expand Down

0 comments on commit ad00b58

Please sign in to comment.