Replication:introduce a state machine for replication