<commit_before>package peergos.shared.mutable;

import peergos.shared.cbor.*;
import peergos.shared.crypto.asymmetric.*;
import peergos.shared.crypto.hash.*;

import java.util.*;
import java.util.concurrent.*;

public interface PointerCache {

    CompletableFuture<Boolean> put(PublicKeyHash owner, PublicKeyHash writer, byte[] writerSignedBtreeRootHash);

    CompletableFuture<Optional<byte[]>> get(PublicKeyHash owner, PublicKeyHash writer);

    default boolean doUpdate(Optional<byte[]> current, byte[] update, PublicSigningKey signer) {
        if (current.isPresent() && Arrays.equals(current.get(), update))
            return false;
        Optional<PointerUpdate> currentVal = current.map(CborObject::fromByteArray).map(PointerUpdate::fromCbor);

        PointerUpdate newVal = PointerUpdate.fromCbor(CborObject.fromByteArray(signer.unsignMessage(update)));

        if (currentVal.isPresent() && currentVal.get().sequence.isPresent()) {
            long currentSeq = currentVal.get().sequence.get();
            if (newVal.sequence.isEmpty() || newVal.sequence.get() < currentSeq)
                throw new IllegalStateException("Invalid pointer update! Sequence number must increase.");
        }
        return true;
    }
}
<commit_msg>doUpdate method bugfix<commit_after>package peergos.shared.mutable;

import peergos.shared.cbor.*;
import peergos.shared.crypto.asymmetric.*;
import peergos.shared.crypto.hash.*;

import java.util.*;
import java.util.concurrent.*;

public interface PointerCache {

    CompletableFuture<Boolean> put(PublicKeyHash owner, PublicKeyHash writer, byte[] writerSignedBtreeRootHash);

    CompletableFuture<Optional<byte[]>> get(PublicKeyHash owner, PublicKeyHash writer);

    default boolean doUpdate(Optional<byte[]> current, byte[] update, PublicSigningKey signer) {
        if (current.isPresent() && Arrays.equals(current.get(), update))
            return false;
        Optional<PointerUpdate> currentVal = current.map(signer::unsignMessage)
                .map(CborObject::fromByteArray)
                .map(PointerUpdate::fromCbor);

        PointerUpdate newVal = PointerUpdate.fromCbor(CborObject.fromByteArray(signer.unsignMessage(update)));

        if (currentVal.isPresent() && currentVal.get().sequence.isPresent()) {
            long currentSeq = currentVal.get().sequence.get();
            if (newVal.sequence.isEmpty() || newVal.sequence.get() < currentSeq)
                throw new IllegalStateException("Invalid pointer update! Sequence number must increase.");
        }
        return true;
    }
}

{'fraction_non_alphanumeric': 0.11936236391912908, 'fraction_numerical': 0.0, 'mean_word_length': 3.9103053435114505, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3304005', 'n_tokens_mistral': 710, 'n_tokens_neox': 693, 'n_words': 140}