# openraft port — membership/t99_issue_584_replication_state_reverted: promoting a learner to a voter
# restarts replication bookkeeping; this must NOT revert the already-established replication progress
# (openraft #584 panicked on a non-monotonic match index). Add learner n2, replicate a batch so its
# match is established at the tip, promote n2 to a voter, and confirm replication continues with no
# match revert (n2 stays at the tip) and the membership becomes voters={1,2}.
add-nodes 1 voters=(1)
----
n1: created voters={1} term=0 commit=0 last=0

campaign 1
----
n1 candidate term=1
n1 leader-changed term=1 lead=1

stabilize
----
ok

propose-conf-change 1 addlearner 2
----
n1 proposed conf-change addlearner n2 at index 2
n1 conf-changed index=2 voters={1} learners={2}

stabilize
----
ok

propose 1 a
----
AppendEntries term=1 prev=1/1 commit=2 entries=[1/2 conf-change 0x120c080212080200000000000000, 1/3 normal 0x010000000000000061]
n1 applied index=3

propose 1 b
----
AppendEntries term=1 prev=1/1 commit=3 entries=[1/2 conf-change 0x120c080212080200000000000000, 1/3 normal 0x010000000000000061, 1/4 normal 0x010000000000000062]
n1 applied index=4

stabilize
----
> n2 recv AppendEntries term=1 prev=1/1 commit=2 entries=[1/2 conf-change 0x120c080212080200000000000000, 1/3 normal 0x010000000000000061]
> n2 recv AppendEntries term=1 prev=1/1 commit=3 entries=[1/2 conf-change 0x120c080212080200000000000000, 1/3 normal 0x010000000000000061, 1/4 normal 0x010000000000000062]
> n2 ready
  AppendResponse term=1 reject hint=0/0
  AppendResponse term=1 reject hint=0/0
  n2 leader-changed term=1 lead=1
> n1 recv AppendResponse term=1 reject hint=0/0
> n1 recv AppendResponse term=1 reject hint=0/0
> n1 ready
  AppendEntries term=1 prev=0/0 commit=4 entries=[1/1 empty, 1/2 conf-change 0x120c080212080200000000000000, 1/3 normal 0x010000000000000061, 1/4 normal 0x010000000000000062]
  AppendEntries term=1 prev=0/0 commit=4 entries=[1/1 empty, 1/2 conf-change 0x120c080212080200000000000000, 1/3 normal 0x010000000000000061, 1/4 normal 0x010000000000000062]
> n2 recv AppendEntries term=1 prev=0/0 commit=4 entries=[1/1 empty, 1/2 conf-change 0x120c080212080200000000000000, 1/3 normal 0x010000000000000061, 1/4 normal 0x010000000000000062]
> n2 recv AppendEntries term=1 prev=0/0 commit=4 entries=[1/1 empty, 1/2 conf-change 0x120c080212080200000000000000, 1/3 normal 0x010000000000000061, 1/4 normal 0x010000000000000062]
> n2 ready
  AppendResponse term=1 match=0
  AppendResponse term=1 match=4
  n2 conf-changed index=2 voters={1} learners={2}
  n2 applied index=3
  n2 applied index=4
> n1 recv AppendResponse term=1 match=0
> n1 recv AppendResponse term=1 match=4
> n1 ready
  AppendEntries term=1 prev=1/4 commit=4 entries=[]
> n2 recv AppendEntries term=1 prev=1/4 commit=4 entries=[]
> n2 ready
  AppendResponse term=1 match=4
> n1 recv AppendResponse term=1 match=4

tick-heartbeat 1
----
Heartbeat term=1 commit=4

stabilize
----
> n2 recv Heartbeat term=1 commit=4
> n2 ready
  HeartbeatResponse term=1
> n1 recv HeartbeatResponse term=1
> n1 ready
  AppendEntries term=1 prev=1/4 commit=4 entries=[]
> n2 recv AppendEntries term=1 prev=1/4 commit=4 entries=[]
> n2 ready
  AppendResponse term=1 match=4
> n1 recv AppendResponse term=1 match=4

raft-log 2
----
n2: commit=4 applied=4 last=4
  1/1 empty
  1/2 conf-change 0x120c080212080200000000000000
  1/3 normal 0x010000000000000061
  1/4 normal 0x010000000000000062

propose-conf-change 1 add 2
----
n1 proposed conf-change add n2 at index 5
AppendEntries term=1 prev=1/4 commit=4 entries=[1/5 conf-change 0x120a12080200000000000000]
n1 conf-changed index=5 voters={1,2}

stabilize
----
> n2 recv AppendEntries term=1 prev=1/4 commit=4 entries=[1/5 conf-change 0x120a12080200000000000000]
> n2 ready
  AppendResponse term=1 match=5
> n1 recv AppendResponse term=1 match=5
> n1 ready
  AppendEntries term=1 prev=1/5 commit=5 entries=[]
> n2 recv AppendEntries term=1 prev=1/5 commit=5 entries=[]
> n2 ready
  AppendResponse term=1 match=5
  n2 conf-changed index=5 voters={1,2}
> n1 recv AppendResponse term=1 match=5

propose 1 c
----
AppendEntries term=1 prev=1/5 commit=5 entries=[1/6 normal 0x010000000000000063]

stabilize
----
> n2 recv AppendEntries term=1 prev=1/5 commit=5 entries=[1/6 normal 0x010000000000000063]
> n2 ready
  AppendResponse term=1 match=6
> n1 recv AppendResponse term=1 match=6
> n1 ready
  AppendEntries term=1 prev=1/6 commit=6 entries=[]
  n1 applied index=6
> n2 recv AppendEntries term=1 prev=1/6 commit=6 entries=[]
> n2 ready
  AppendResponse term=1 match=6
  n2 applied index=6
> n1 recv AppendResponse term=1 match=6

raft-state
----
n1: leader term=1 lead=1
n2: follower term=1 lead=1

conf-state 1
----
n1: voters={1,2}

raft-log 2
----
n2: commit=6 applied=6 last=6
  1/1 empty
  1/2 conf-change 0x120c080212080200000000000000
  1/3 normal 0x010000000000000061
  1/4 normal 0x010000000000000062
  1/5 conf-change 0x120a12080200000000000000
  1/6 normal 0x010000000000000063

