From f4ef38c42f4cafd637163c8e13ba2b8c9426a64c Mon Sep 17 00:00:00 2001 From: DanS Date: Fri, 20 Mar 2026 06:11:38 -0500 Subject: [PATCH] fix sapling activation height and consensus branch id --- common/common.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/common/common.go b/common/common.go index bda1efc..cad904f 100644 --- a/common/common.go +++ b/common/common.go @@ -40,17 +40,34 @@ func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int, chainName := f.(map[string]interface{})["chain"].(string) - upgradeJSON := f.(map[string]interface{})["upgrades"] - saplingJSON := upgradeJSON.(map[string]interface{})["76b809bb"] // Sapling ID - saplingHeight := saplingJSON.(map[string]interface{})["activationheight"].(float64) + // DragonX has Sapling active from block 1 but sets NO_ACTIVATION_HEIGHT in + // chainparams, so dragonxd omits it from the upgrades map. Fall back to + // height 1 when the key is absent. + saplingHeight := float64(1) + upgradeJSON, ok := f.(map[string]interface{})["upgrades"] + if ok { + if upgradesMap, ok := upgradeJSON.(map[string]interface{}); ok { + if saplingJSON, ok := upgradesMap["76b809bb"]; ok { + saplingHeight = saplingJSON.(map[string]interface{})["activationheight"].(float64) + } + } + } blockHeight := f.(map[string]interface{})["headers"].(float64) difficulty := f.(map[string]interface{})["difficulty"].(float64) longestchain := f.(map[string]interface{})["longestchain"].(float64) notarized := f.(map[string]interface{})["notarized"].(float64) - consensus := f.(map[string]interface{})["consensus"] - branchID := consensus.(map[string]interface{})["nextblock"].(string) + // DragonX always uses Sapling consensus rules but CurrentEpochBranchId() + // returns Sprout (0) for full nodes because the activation heights are + // set to NO_ACTIVATION_HEIGHT. Override to the correct Sapling branch ID. + branchID := "76b809bb" + consensus, ok := f.(map[string]interface{})["consensus"] + if ok { + if nextblock, ok := consensus.(map[string]interface{})["nextblock"].(string); ok && nextblock != "00000000" { + branchID = nextblock + } + } return int(saplingHeight), int(blockHeight), chainName, branchID, int(difficulty), int(longestchain), int(notarized), nil }