github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/pkg/fftypes/pin.go (about) 1 // Copyright © 2021 Kaleido, Inc. 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package fftypes 18 19 // Pin represents a ledger-pinning event that has been 20 // detected from the blockchain, in the sequence that it was detected. 21 // 22 // A batch contains many messages, and each of those messages can be on a different 23 // topic (or topics) 24 // All messages on the same topic must be processed in the order that 25 // the batch pinning events arrive from the blockchain. 26 // 27 // As we need to correlate the on-chain events, with off-chain data that might 28 // arrive at a different time (or never), we "park" all pinned sequences first, 29 // then only complete them (and generate the associated events) once all the data 30 // has been assembled for all messages on that sequence, within that batch. 31 // 32 // We might park the pin first (from the blockchain), or park the batch first 33 // (if it arrived first off-chain). 34 // There's a third part as well that can block a message, which is large blob data 35 // moving separately to the batch. If we get the private message, then the batch, 36 // before receiving the blob data - we have to upgrade a batch-park, to a pin-park. 37 // This is because the sequence must be in the order the pins arrive. 38 // 39 type Pin struct { 40 Sequence int64 `json:"sequence,omitempty"` 41 Masked bool `json:"masked,omitempty"` 42 Hash *Bytes32 `json:"hash,omitempty"` 43 Batch *UUID `json:"batch,omitempty"` 44 Index int64 `json:"index,omitempty"` 45 Dispatched bool `json:"dispatched,omitempty"` 46 Created *FFTime `json:"created,omitempty"` 47 } 48 49 func (p *Pin) LocalSequence() int64 { 50 return p.Sequence 51 }