Skip to content

Commit

Permalink
adding immediate termination
Browse files Browse the repository at this point in the history
  • Loading branch information
Janis Erdmanis committed Apr 29, 2024
1 parent 49509b6 commit 75b2dac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Core/Model/audit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ function audit_members(ledger::BraidChainLedger)
id(member_cert) == id(record) || return false # must be consistent
pop!(identities, id(member_cert))

if generator(member_cert) == g # immediate termination
pop!(members, pseudonym(member_cert))
end
end
end
end
Expand Down
12 changes: 9 additions & 3 deletions src/Server/Controllers/braidchain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ roll(chain::BraidChainController) = chain.roll

blacklist(chain::BraidChainController) = chain.blacklist

termination_bitmask(chain::BraidChainController) = copy(chain.termination_bitmask) # An alternative is to copy it at push which may be better
termination_bitmask(chain::BraidChainController) = copy(chain.termination_bitmask)
termination_bitmask(chain::BraidChainController, N::Int) = termination_bitmask(chain.ledger, N)

"""
generator(ledger::BraidChainController)
Expand Down Expand Up @@ -410,8 +411,13 @@ function Base.push!(chain::BraidChainController, termination::Termination)
push!(chain.blacklist, termination.identity)

if termination.index != 0
chain.termination_bitmask[termination.index] = true
pop!(chain.roll, termination.identity)
chain.termination_bitmask[termination.index] = true
pop!(chain.roll, termination.identity)

member_cert = chain[termination.index]
if generator(member_cert) == generator(chain)
pop!(chain.members, pseudonym(member_cert)) # immediate termination
end
end

unsafe_push!(chain, termination)
Expand Down
19 changes: 19 additions & 0 deletions test/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ g = generator(BRAID_CHAIN)
access = Membership(admission, g, pseudonym(fiona, g)) |> approve(fiona)
@test_throws AssertionError record!(BRAID_CHAIN, access)

# Imediate termination after registration

ticketid_lucy = TicketID("Lucy")
invite_lucy = enlist(ticketid_lucy)
lucy = Signer(crypto, 7)
lucy_access, lucy_ack = enroll(lucy, invite_lucy)

@test id(lucy) in roll(BRAID_CHAIN)
@test pseudonym(lucy, BRAID_CHAIN.generator) in members(BRAID_CHAIN)

termination = Termination(Model.index(lucy_ack), id(lucy)) |> approve(REGISTRAR.signer)
record!(BRAID_CHAIN, termination)

@test !(id(lucy) in roll(BRAID_CHAIN))
@test !(pseudonym(lucy, BRAID_CHAIN.generator) in members(BRAID_CHAIN)) # reverse needs to be true

# Termination with braid reset

N = Model.index(david_ack)
Expand All @@ -181,6 +197,9 @@ record!(BRAID_CHAIN, termination)
@test termination_bitmask(BRAID_CHAIN)[N]
@test pseudonym(david, BRAID_CHAIN.generator) in members(BRAID_CHAIN)

braidwork = braid(generator(BRAID_CHAIN), members(BRAID_CHAIN), demespec.crypto, demespec, BRAIDER; reset = false)
record!(BRAID_CHAIN, braidwork)

braidwork = braid(generator(BRAID_CHAIN.spec), roll(BRAID_CHAIN), demespec.crypto, demespec, BRAIDER; reset = true)
record!(BRAID_CHAIN, braidwork)
commit!(BRAID_CHAIN, BRAID_CHAIN_RECORDER)
Expand Down

0 comments on commit 75b2dac

Please sign in to comment.