Skip to content
Snippets Groups Projects
Unverified Commit cb1ae9b7 authored by Éloïs's avatar Éloïs
Browse files

[fix] #1214 accept closer heads

parent 9b84d20d
No related branches found
No related tags found
3 merge requests!1222Add startup scripts,!1220Stable/ws2p v1.1 trymerge,!1208Stable/ws2p v1.1
...@@ -164,10 +164,12 @@ export class WS2PCluster { ...@@ -164,10 +164,12 @@ export class WS2PCluster {
const sigOK = verify(head.message, head.sig, pub) const sigOK = verify(head.message, head.sig, pub)
const sigV2OK = (head.messageV2 !== undefined && head.sigV2 !== undefined) ? verify(head.messageV2, head.sigV2, pub):false const sigV2OK = (head.messageV2 !== undefined && head.sigV2 !== undefined) ? verify(head.messageV2, head.sigV2, pub):false
if ((sigV2OK && sigOK) || sigOK) { if ((sigV2OK && sigOK) || sigOK) {
// Already known? // Already known or more recent or closer ?
if (!this.headsCache[fullId] || this.headsCache[fullId].blockstamp !== blockstamp) { const step = this.headsCache[fullId].step || 0
// More recent? if (!this.headsCache[fullId] // unknow head
if (!this.headsCache[fullId] || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp)) { || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp) // more recent head
|| (head.step !== undefined && head.step < step && this.headsCache[fullId].blockstamp === blockstamp) // closer head
) {
// Check that issuer is a member and that the block exists // Check that issuer is a member and that the block exists
const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub)) const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub))
if (isAllowed) { if (isAllowed) {
...@@ -189,7 +191,6 @@ export class WS2PCluster { ...@@ -189,7 +191,6 @@ export class WS2PCluster {
} }
} }
} }
}
} else { } else {
throw "HEAD_MESSAGE_WRONGLY_SIGNED" throw "HEAD_MESSAGE_WRONGLY_SIGNED"
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment