mirror of https://codeberg.org/pzp/pzp-sync.git
refactor algorithm commit()
This commit is contained in:
parent
fc30b3e2d2
commit
cfb186c0fe
|
@ -6,10 +6,8 @@ const { parseGoal } = require('./goal')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('./range').Range} Range
|
* @typedef {import('./range').Range} Range
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {import('./goal').Goal} Goal
|
* @typedef {import('./goal').Goal} Goal
|
||||||
|
* @typedef {import('ppppp-db/msg-v3').Msg} Msg
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function countIter(iter) {
|
function countIter(iter) {
|
||||||
|
@ -160,10 +158,17 @@ class Algorithm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async commit(rootID, newMsgs, goal, myWantRange) {
|
/**
|
||||||
// Filter out dataful newMsgs that are not in my want-range
|
* Filter out msgs I didn't actually ask for. "Trust but verify"
|
||||||
|
* @param {string} rootID
|
||||||
|
* @param {Array<Msg>} msgs
|
||||||
|
* @param {Range} myWantRange
|
||||||
|
* @returns {Array<Msg>}
|
||||||
|
*/
|
||||||
|
#filterReceivedMsgs(rootID, msgs, myWantRange) {
|
||||||
const [minWant, maxWant] = myWantRange
|
const [minWant, maxWant] = myWantRange
|
||||||
const validNewMsgs = newMsgs
|
|
||||||
|
const validNewMsgs = msgs
|
||||||
.filter((msg) => {
|
.filter((msg) => {
|
||||||
const depth = msg.metadata.tangles[rootID]?.depth ?? 0
|
const depth = msg.metadata.tangles[rootID]?.depth ?? 0
|
||||||
if (depth === 0 && MsgV3.getMsgID(msg) !== rootID) {
|
if (depth === 0 && MsgV3.getMsgID(msg) !== rootID) {
|
||||||
|
@ -181,6 +186,12 @@ class Algorithm {
|
||||||
return aDepth - bDepth
|
return aDepth - bDepth
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return validNewMsgs
|
||||||
|
}
|
||||||
|
|
||||||
|
async commit(rootID, newMsgs, goal, myWantRange) {
|
||||||
|
const validNewMsgs = this.#filterReceivedMsgs(rootID, newMsgs, myWantRange)
|
||||||
|
|
||||||
// TODO: Simulate adding this whole tangle, and check if it's valid
|
// TODO: Simulate adding this whole tangle, and check if it's valid
|
||||||
|
|
||||||
// Add new messages
|
// Add new messages
|
||||||
|
|
Loading…
Reference in New Issue