Skip to content

add_link is not compliant with Duniter 1.7

In Duniter 1.7, the wotb module's add_link method checks if a link already exists before adding it and incrementing the issuer's count of emitted certifications:

bool Node::addLinkTo(Node* to) {
    if(mNbIssued >= mWot->getMaxCert() ||
      to == this ||
      to->hasLinkFrom(this)) { // <-- the condition
        return false;
    }

    to->mCert.push_back(this);
    mNbIssued++;
    return true;
}

But in Duniter 1.8 using duniter-core/dubp-wot, this condition is not included:

fn add_link(&mut self, source: WotId, target: WotId) -> NewLinkResult {
    if source == target {
        NewLinkResult::SelfLinkingForbidden()
    } else if source.0 >= self.size() {
        NewLinkResult::UnknownSource()
    } else if target.0 >= self.size() {
        NewLinkResult::UnknownTarget()
    } else if self.nodes[source.0].issued_count >= self.max_links {
        NewLinkResult::AllCertificationsUsed(self.nodes[target.0].links_source.len())
    } else { // <-- Missing a `else if self.nodes[target.0].links_source.contains(&source)` test
        self.nodes[source.0].issued_count += 1;
        self.nodes[target.0].links_source.insert(source);
        NewLinkResult::Ok(self.nodes[target.0].links_source.len())
    }
}

This leads to a different behavior between 1.7 (C++) and 1.8 (Rust) versions for certifications replay where the Rust version increments the issued_count (decrement the issuer's stock) whereas the C++ version does not.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information