package lockstep import ( "encoding/binary" "ripple/types" ) func (l *Lockstep) ProcessInbound(tx types.Transaction) { id := tx.Identifier instr := tx.Instruction localTC := l.st.Storage.MustGetAccount(id).TurnCounter inboundTC := binary.BigEndian.Uint32(instr.Arguments[:4]) instr.Arguments = instr.Arguments[4:] inTurn := l.inTurnFromTC(id, localTC) if inboundTC == localTC { if inTurn { if l.processInboundProposal(id, instr) { l.doTurn(id) } } else { if l.processInboundValidation(id, instr) { l.doTurn(id) } } } else if inboundTC + 1 == localTC && !inTurn { l.sendLastValidated(id) } } func (l *Lockstep) processInboundValidation(id types.UserIdentifier, instr types.Instruction) bool { if isExternalCmd(instr.Command) { peekInstr, ok := l.peek(id) if ok && compareData(instr, peekInstr) { _, _ = l.dequeue(id) } } instr.Command = cmdToggleLSB(instr.Command) if err := l.stateTransition(id, instr); err != nil { return false } return true } func (l *Lockstep) processInboundProposal(id types.UserIdentifier, instr types.Instruction) bool { instr.Command = cmdToExternalCmd(instr.Command) if err := l.stateTransition(id, instr); err != nil { return false } l.sendValidated(id, instr) return true }