@@ -777,13 +777,64 @@ func (n *NetworkHarness) RestartNodeNoUnlock(node *HarnessNode,
777777 )
778778}
779779
780+ // suspendCfg contains any configurations related to suspending a node. This may
781+ // change the way the node starts up again.
782+ type suspendCfg struct {
783+ upgrade bool
784+ downgrade string
785+ }
786+
787+ // SuspendOption is a functional option that may change the suspend
788+ // configuration.
789+ type SuspendOption func (cfg * suspendCfg )
790+
791+ // WithUpgrade is a functional option which indicates that the node should be
792+ // upgraded to the latest version of LiT.
793+ func WithUpgrade () SuspendOption {
794+ return func (cfg * suspendCfg ) {
795+ cfg .upgrade = true
796+ }
797+ }
798+
799+ // WithDowngrade is a functional option which indicates that the node should be
800+ // downgraded to the defined LiT version.
801+ func WithDowngrade (version string ) SuspendOption {
802+ return func (cfg * suspendCfg ) {
803+ cfg .downgrade = version
804+ }
805+ }
806+
780807// SuspendNode stops the given node and returns a callback that can be used to
781- // start it again.
782- func (n * NetworkHarness ) SuspendNode (node * HarnessNode ) (func () error , error ) {
808+ // start it again. If the upgrade flag is set then any backwards compatibility
809+ // version that the node was running previously will be eliminated, forcing it
810+ // to use the current (latest) build.
811+ func (n * NetworkHarness ) SuspendNode (node * HarnessNode ,
812+ opts ... SuspendOption ) (func () error , error ) {
813+
783814 if err := node .Stop (); err != nil {
784815 return nil , err
785816 }
786817
818+ cfg := & suspendCfg {}
819+
820+ for _ , opt := range opts {
821+ opt (cfg )
822+ }
823+
824+ // If the upgrade flag was set, delete any entry from the backwards
825+ // compatibility map. This will force the node to use the latest build
826+ // of LiT.
827+ if cfg .upgrade {
828+ delete (n .backwardCompat , node .Name ())
829+ }
830+
831+ // If a downgrade version was defined, update the backwards
832+ // compatibility entry with that version for this LiT node. This will
833+ // force the node to start up using the defined version.
834+ if cfg .downgrade != "" {
835+ n .backwardCompat [node .Name ()] = cfg .downgrade
836+ }
837+
787838 restart := func () error {
788839 return node .Start (
789840 n .litdBinary , n .backwardCompat , n .lndErrorChan , true ,
@@ -822,8 +873,10 @@ func (n *NetworkHarness) StopNode(node *HarnessNode) error {
822873}
823874
824875// StopAndBackupDB backs up the database of the target node.
825- func (n * NetworkHarness ) StopAndBackupDB (node * HarnessNode ) error {
826- restart , err := n .SuspendNode (node )
876+ func (n * NetworkHarness ) StopAndBackupDB (node * HarnessNode ,
877+ opts ... SuspendOption ) error {
878+
879+ restart , err := n .SuspendNode (node , opts ... )
827880 if err != nil {
828881 return err
829882 }
@@ -847,8 +900,10 @@ func (n *NetworkHarness) StopAndBackupDB(node *HarnessNode) error {
847900
848901// StopAndRestoreDB stops the target node, restores the database from a backup
849902// and starts the node again.
850- func (n * NetworkHarness ) StopAndRestoreDB (node * HarnessNode ) error {
851- restart , err := n .SuspendNode (node )
903+ func (n * NetworkHarness ) StopAndRestoreDB (node * HarnessNode ,
904+ opts ... SuspendOption ) error {
905+
906+ restart , err := n .SuspendNode (node , opts ... )
852907 if err != nil {
853908 return err
854909 }
0 commit comments