added methods in post consensus persistence to increase and decrease token denom; fixed transaction syncing by making DB operations atomic#645
Draft
arnabghose997 wants to merge 25 commits intorelease-v1from
Conversation
…token denom; fixed transaction syncing by making DB operations atomic
SendTokensRequest previously carried only token lists and a flag. The receiver-side sync handler (SendTokens) needs the full TransactionInfo and Signature to call PersistPostConsensus directly, so both fields are added with JSON tags matching the existing naming convention.
…nce tracking post_consensus_persistence.go: - Add SkipSignatureVerification flag to PostConsensusPersistenceRequest so the receiver can call PersistPostConsensus without re-verifying the initiator signature using its own DID keys (which would always fail). - validateTransferChainContinuity: tighten the token status check per execution role. Initiator/Quorum: token must be Free or Locked. Receiver: token must be Free, Locked, or Transferred. Transferred covers the case where a token returns to the node that originally sent it. Terminal states (Burnt, Orphaned, ChainSyncIssue, BeingDoubleSpent) are explicitly rejected for all roles. - Add upsertTokenDenomDeltas: updates token_denom within the same DB transaction after token state upsert. Receiver increments denom count; initiator decrements. Quorum role makes no change (pledged tokens tracked via token_status only). post_consensus_payload_builder.go: - Add TokenValue float64 and TokenTypeName string to persistenceTokenInput and propagate them from TokenInfo in collectPersistenceTokenInputs. - Receiver genesis handling: when a token arrives at a node for the first time (not in DB), synthesize a models.Token using input.TokenValue as the primary source and util.GetTokenValueFromTokenID as fallback. Error explicitly if neither source yields a non-zero value (prevents silent token_denom skip). Force PreviousTransactionID="" so position=0 is assigned, bypassing the validateTransferChainContinuity ownership check for a brand-new token. - Pass token type name through appendInputs so genesis synthesis can set the correct TokenType when building the synthesized Token struct.
CollectRBTTokens was building TokenInfo with only TokenID and PreviousTransactionID set, leaving TokenValue=0 and DID="" in the constructed transfer list. Both fields are part of TransactionInfo which is hashed and signed, so they must be populated. Set TokenValue and DID from the source models.Token for both the non-split path (direct denomination match) and the split path (post performTokenSplit child tokens).
…yntax token.go: - Add ReleaseAllLockedRBTTokensForDID: resets all Locked RBT tokens for a DID back to Free. Called on initiator-side transaction failure after LockTokensForSplit to prevent tokens from staying permanently locked. - Add ReleaseNonSelectedLockedRBTTokensForDID: resets Locked RBT tokens back to Free excluding a specified subset. Called by the quorum pledge handler after pledge selection to release candidates not chosen for the pledge. - Fix GetTokensFromDenomMap SQL: LIMIT=$4 is invalid PostgreSQL syntax for a parameterised limit; corrected to LIMIT $4. token_lock.go: - Add structured log line to LockTokensForSplit for observability. quorum_stubs.go: - Implement UnlockLockedTokens stub: executes an UPDATE to reset Locked tokens back to Free for a given DID and token ID list. Replaces the previous no-op placeholder that prevented quorum-side token unlock from functioning.
…handler initiateTransaction: - Register deferred ReleaseAllLockedRBTTokensForDID BEFORE calling BuildTransactionInfoFromRequest. LockTokensForSplit (called inside BuildTransactionInfoFromRequest) commits locks to the DB immediately; if BuildTransactionInfoFromRequest fails (e.g. insufficient balance), the defer must already be registered to release those locks. - Fix quorum signature verification: use SetupForienDID with the quorum DID instead of the initiator's DIDCrypto. The initiator's key cannot verify a signature made by the quorum. - Call PersistPostConsensus with ExecutionRoleInitiator after consensus succeeds to mark transferred tokens as Transferred and decrement token_denom. On success, release non-selected locked tokens. On failure, the deferred full-release fires. - Send tokens to the receiver asynchronously via sendTokensToReceiver goroutine so the initiator HTTP response is not blocked on receiver availability. SendTokens (APISendTokens handler): - Replace the previous syncTransactionTokens call (which relied on a broken stub) with a direct PersistPostConsensus call using ExecutionRoleReceiver and SkipSignatureVerification=true. The receiver persists the incoming transaction, updates token states to Free, and increments token_denom.
quorum_initiator.go (requestPledgeTokenHandler): - On pledge selection failure: call ReleaseAllLockedRBTTokensForDID to free the tokens locked by LockTokensForSplit in ReqPledgeToken. Without this, a failed pledge attempt left the quorum's entire token set permanently locked, preventing any subsequent transaction. - On pledge success: call ReleaseNonSelectedLockedRBTTokensForDID to free only the candidate tokens not chosen for the pledge. Selected pledge tokens must remain Locked so that PledgeTokens (called during consensus) can verify their state before transitioning them to Pledged. - Improve initiateConsensusHandler: use SetupDID (not SetupForienDID) so the quorum uses its own DID key for signing; add structured log output. transaction_builder.go: - Include RBT amount from sub-requests in totalAmount accumulation via GetRBTAmount() so multi-part requests are costed correctly. consensus/consensus.go: - Add structured log line to ReqPledgeToken for observability.
peer.go (AddPeerDetails): - Add defensive AlgoID resolution when the caller passes AlgoID=0 (Go zero value). The did_algo table uses a 1-based GENERATED ALWAYS AS IDENTITY column, so id=0 does not exist and the algo_id_fk FK constraint fired on every transaction. Fix: look up the SECP256K1 algo ID via GetDidAlgoIDByName before calling CreateOrUpdateDID. Protects all current callers (TxnCallBack, token-sync callback, isDIDInArbitaryAddr) and any future callers. fullnode.go (SubscribeTxnSetup): - Add idempotency guard: catch the "topic already subscribed" error from SubscribeTopic and return at Debug level. SetupQuorum is called once per quorum DID; nodes with 2+ quorum DIDs were emitting an ERROR on every subsequent call. Real IPFS subscription failures remain at Error level. - Include error value in "failed to add publisher info to DB" log. token.go: - Include error value in "failed to add publisher info to DB" log. util/transaction.go (PublishTransaction): - Set BlockHash to the transaction ID (SHA3-256 hex) on EventTransaction. Previously BlockHash was always "", causing every transaction to collide at the same dedup key in TxnCallBack's processedTxns sync.Map — all transactions after the first were silently dropped as duplicates.
core.go: - Call w.SetDidDir(c.didDir) after wallet init so the wallet has access to the DID directory for signature verification in PersistPostConsensus. ipfs.go: - Add ensureLibp2pStreamMounting: patches the IPFS config file to set Experimental.Libp2pStreamMounting=true before the daemon starts. This enables stream multiplexing required for inter-node RPC communication. Operates on the config file directly (not via API) so it works on both first-run and subsequent runs without a running daemon. command/command.go: - Bump version from 0.1_keys to 0.2.
- Replace TransactionInfo+InitiatorSignature fields with Transaction *Transactions
- Initiator builds Transactions{ID, Info, Signature} from transactionInfo + initiatorSignature
- Serializes TransactionInfo bytes via models.SerializeTransactionInfo
- Marshals Signature{InitiatorSignature} to sigBytes via json.Marshal
…ateConsensus internals - Add 5-check validation pipeline in initiateConsensusHandler before InitiateConsensus call - Validate: InfoFields, TxIDIntegrity, NewTokenContent per RBT, ValueAndPledge, InitiatorSignature - InitiateConsensus now unmarshals Transaction.Info/Signature internally, uses Transaction.ID directly - Remove commented-out ValidateTransaction block from consensus.go - Add encoding/json import to quorum_initiator.go
- Add missing Network field assignment in BuildTransactionInfoFromRequest - networkMode was accepted as a parameter but never written to txInfo - Empty string caused ValidateTransactionInfoFields to reject consensus with "invalid network" error at every quorum participant
NewCore already receives networkMode from the config (UserConfig.Core.NetworkMode). Previously it was decomposed into three booleans then recomputed back to a string via util.GetNetworkMode on every transaction. Store the string directly on Core and use c.networkMode at the two call sites that need the string.
…ignature shape Remove the Transactions wrapper introduced in 260403-18f. ConsensusRequest now carries TransactionInfo pointer and InitiatorSignature string directly, eliminating unnecessary json.Marshal/Unmarshal round-trips on the consensus hot path. - types/models/consensus.go: replace Transaction *Transactions with TransactionInfo *TransactionInfo + InitiatorSignature string; fix json tag typo transactioInfo -> transactionInfo - core/transaction.go: remove SerializeTransactionInfo + json.Marshal(Signature) + Transactions struct build; set consensusRequest fields directly - core/quorum_initiator.go: direct field access via consensusRequest.TransactionInfo; remove json.Unmarshal blocks and TransactionIDIntegrityCheck call; compute txID via util.GetTransactionID for logging; remove encoding/json import - core/consensus/consensus.go: direct field access; compute transactionId and transactionInfoBytes internally; use consensusRequest.InitiatorSignature directly
Legacy GORM-managed tables pub_sub_txn_info and full_node_txn_history_info may still carry a block_hash column from older schema versions. The field was always set to txID and is a vestige of the removed block package. This migration drops it with IF EXISTS guards and validates transaction_id integrity before any DDL executes.
- EventTransaction: BlockHash -> TransactionID - PubSubTxnInfo: drop BlockHash, promote TransactionID to primaryKey - FailedTransaction: BlockHash -> TxnID (column tag unchanged) - FullNodeTxnHistoryInfo: drop BlockHash field - NFTEvent: drop NFTBlockHash - NewContractEvent: drop SmartContractBlockHash - NewState (core/smart_contract.go): drop ConBlockHash - AllToken (core/types.go): drop BlockHash (dead code cleanup) - SyncedRBT/FT/NFT/SmartContract: drop BlockHash from all four - BlockValidationResult: rename BlockHash -> BlockID for clarity
- util/transaction.go: EventTransaction.BlockHash -> TransactionID - core/fullnode.go: dedup and logs use TransactionID; FailedTransaction.BlockHash -> TxnID - core/publisher.go: drop BlockHash from FullNodeTxnHistoryInfo literals (RBT and FT loops) - core/token.go: all three PubSubTxnInfo literals drop BlockHash; double-spend comparison uses txnID vs existingTxnID; all four Synced* struct literals and update assignments drop BlockHash; ReadTokenFromFullnodeTokensTable returns TransactionID instead of BlockHash - client/smart_contract.go: PublishNewEvent drops block parameter and SmartContractBlockHash - command/command.go: remove newContractBlock field and -sctBlockHash flag - command/smartContract.go: remove fourth argument from PublishNewEvent call
… removal GetHash() results assigned to latestBlockHash and blockHash were only ever used to populate the BlockHash struct field (now removed). Replace assignments with _ to keep the GetHash() calls without triggering unused-variable errors.
…lper The bug: planTokenSplit read currentTokenElems.Level (the token-mapping level, e.g. 10001) and compared it against denom-tree level bounds (0-6), causing the guard to always trigger and all split operations to fail. Fix: add ParseTokenLevel(tokenID) to util/token_denom.go as the single source of truth for tokenID -> denom-tree level (0-6) conversion. planTokenSplit now calls util.ParseTokenLevel instead of reading the token-mapping level field. GetTokenValueFromTokenID refactored to use ParseTokenLevel internally.
…enID split sites Audit of all 7 tokenID strings.Split sites confirmed: - ValidateNewTokenContent and ValidateGenuineTokenCreator intentionally use the token-mapping level (10001+) for TokenMap lookups, not the denom-tree level (0-6). Added clarifying comments so future readers do not conflate them. - ValidateGenuineTokenCreator level==1 guard noted as dead code for current token format (10001+ offset scheme). - All other sites (ValidateTokenIDRelatedChecks, CheckWholeToken, diagnostic, validate, ft.go) are safe -- they only use element count or token number, never the level field for denom-tree purposes.
…error Format string had 4 %s/%v verbs but only 3 arguments were supplied, causing go vet to flag the call and the error message to be malformed at runtime.
Pure code-organisation move — co-locate the real unlock operation with the other Lock*/Unlock* functions in token_lock.go rather than leaving it in quorum_stubs.go alongside TODO phase07 stubs. No behaviour change; no call-site changes; unused imports removed from quorum_stubs.go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.