Fix ln close classification logic
This commit is contained in:
		
							parent
							
								
									9bb897307f
								
							
						
					
					
						commit
						022785a555
					
				@ -289,6 +289,24 @@ class NetworkSyncService {
 | 
				
			|||||||
    1. Mutually closed
 | 
					    1. Mutually closed
 | 
				
			||||||
    2. Forced closed
 | 
					    2. Forced closed
 | 
				
			||||||
    3. Forced closed with penalty
 | 
					    3. Forced closed with penalty
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ┌────────────────────────────────────┐       ┌────────────────────────────┐
 | 
				
			||||||
 | 
					    │ outputs contain revocation script? ├──yes──► force close w/ penalty = 3 │
 | 
				
			||||||
 | 
					    └──────────────┬─────────────────────┘       └────────────────────────────┘
 | 
				
			||||||
 | 
					                   no
 | 
				
			||||||
 | 
					    ┌──────────────▼──────────────────────────┐
 | 
				
			||||||
 | 
					    │ outputs contain other lightning script? ├──┐
 | 
				
			||||||
 | 
					    └──────────────┬──────────────────────────┘  │
 | 
				
			||||||
 | 
					                   no                           yes
 | 
				
			||||||
 | 
					    ┌──────────────▼─────────────┐               │
 | 
				
			||||||
 | 
					    │ sequence starts with 0x80  │      ┌────────▼────────┐
 | 
				
			||||||
 | 
					    │           and              ├──────► force close = 2 │
 | 
				
			||||||
 | 
					    │ locktime starts with 0x20? │      └─────────────────┘
 | 
				
			||||||
 | 
					    └──────────────┬─────────────┘
 | 
				
			||||||
 | 
					                   no
 | 
				
			||||||
 | 
					         ┌─────────▼────────┐
 | 
				
			||||||
 | 
					         │ mutual close = 1 │
 | 
				
			||||||
 | 
					         └──────────────────┘
 | 
				
			||||||
  */
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private async $runClosedChannelsForensics(): Promise<void> {
 | 
					  private async $runClosedChannelsForensics(): Promise<void> {
 | 
				
			||||||
@ -326,36 +344,31 @@ class NetworkSyncService {
 | 
				
			|||||||
              lightningScriptReasons.push(lightningScript);
 | 
					              lightningScriptReasons.push(lightningScript);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          if (lightningScriptReasons.length === outspends.length
 | 
					          const filteredReasons = lightningScriptReasons.filter((r) => r !== 1);
 | 
				
			||||||
            && lightningScriptReasons.filter((r) => r === 1).length === outspends.length) {
 | 
					          if (filteredReasons.length) {
 | 
				
			||||||
            reason = 1;
 | 
					            if (filteredReasons.some((r) => r === 2 || r === 4)) {
 | 
				
			||||||
          } else {
 | 
					              reason = 3;
 | 
				
			||||||
            const filteredReasons = lightningScriptReasons.filter((r) => r !== 1);
 | 
					 | 
				
			||||||
            if (filteredReasons.length) {
 | 
					 | 
				
			||||||
              if (filteredReasons.some((r) => r === 2 || r === 4)) {
 | 
					 | 
				
			||||||
                reason = 3;
 | 
					 | 
				
			||||||
              } else {
 | 
					 | 
				
			||||||
                reason = 2;
 | 
					 | 
				
			||||||
              }
 | 
					 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
              /*
 | 
					              reason = 2;
 | 
				
			||||||
                We can detect a commitment transaction (force close) by reading Sequence and Locktime
 | 
					            }
 | 
				
			||||||
                https://github.com/lightning/bolts/blob/master/03-transactions.md#commitment-transaction
 | 
					          } else {
 | 
				
			||||||
              */
 | 
					            /*
 | 
				
			||||||
              let closingTx: IEsploraApi.Transaction | undefined;
 | 
					              We can detect a commitment transaction (force close) by reading Sequence and Locktime
 | 
				
			||||||
              try {
 | 
					              https://github.com/lightning/bolts/blob/master/03-transactions.md#commitment-transaction
 | 
				
			||||||
                closingTx = await bitcoinApi.$getRawTransaction(channel.closing_transaction_id);
 | 
					            */
 | 
				
			||||||
              } catch (e) {
 | 
					            let closingTx: IEsploraApi.Transaction | undefined;
 | 
				
			||||||
                logger.err(`Failed to call ${config.ESPLORA.REST_API_URL + '/tx/' + channel.closing_transaction_id}. Reason ${e instanceof Error ? e.message : e}`);
 | 
					            try {
 | 
				
			||||||
                continue;
 | 
					              closingTx = await bitcoinApi.$getRawTransaction(channel.closing_transaction_id);
 | 
				
			||||||
              }
 | 
					            } catch (e) {
 | 
				
			||||||
              const sequenceHex: string = closingTx.vin[0].sequence.toString(16);
 | 
					              logger.err(`Failed to call ${config.ESPLORA.REST_API_URL + '/tx/' + channel.closing_transaction_id}. Reason ${e instanceof Error ? e.message : e}`);
 | 
				
			||||||
              const locktimeHex: string = closingTx.locktime.toString(16);
 | 
					              continue;
 | 
				
			||||||
              if (sequenceHex.substring(0, 2) === '80' && locktimeHex.substring(0, 2) === '20') {
 | 
					            }
 | 
				
			||||||
                reason = 2; // Here we can't be sure if it's a penalty or not
 | 
					            const sequenceHex: string = closingTx.vin[0].sequence.toString(16);
 | 
				
			||||||
              } else {
 | 
					            const locktimeHex: string = closingTx.locktime.toString(16);
 | 
				
			||||||
                reason = 1;
 | 
					            if (sequenceHex.substring(0, 2) === '80' && locktimeHex.substring(0, 2) === '20') {
 | 
				
			||||||
              }
 | 
					              reason = 2; // Here we can't be sure if it's a penalty or not
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					              reason = 1;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          if (reason) {
 | 
					          if (reason) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user