node_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package node
  17. import (
  18. "errors"
  19. "fmt"
  20. "io"
  21. "io/ioutil"
  22. "net"
  23. "net/http"
  24. "os"
  25. "reflect"
  26. "strings"
  27. "testing"
  28. "github.com/ethereum/go-ethereum/crypto"
  29. "github.com/ethereum/go-ethereum/ethdb"
  30. "github.com/ethereum/go-ethereum/p2p"
  31. "github.com/ethereum/go-ethereum/plugin"
  32. "github.com/ethereum/go-ethereum/rpc"
  33. "github.com/stretchr/testify/assert"
  34. )
  35. var (
  36. testNodeKey, _ = crypto.GenerateKey()
  37. )
  38. func testNodeConfig() *Config {
  39. return &Config{
  40. Name: "test node",
  41. P2P: p2p.Config{PrivateKey: testNodeKey},
  42. }
  43. }
  44. // Tests that an empty protocol stack can be closed more than once.
  45. func TestNodeCloseMultipleTimes(t *testing.T) {
  46. stack, err := New(testNodeConfig())
  47. if err != nil {
  48. t.Fatalf("failed to create protocol stack: %v", err)
  49. }
  50. stack.Close()
  51. // Ensure that a stopped node can be stopped again
  52. for i := 0; i < 3; i++ {
  53. if err := stack.Close(); err != ErrNodeStopped {
  54. t.Fatalf("iter %d: stop failure mismatch: have %v, want %v", i, err, ErrNodeStopped)
  55. }
  56. }
  57. }
  58. func TestNodeStartMultipleTimes(t *testing.T) {
  59. stack, err := New(testNodeConfig())
  60. if err != nil {
  61. t.Fatalf("failed to create protocol stack: %v", err)
  62. }
  63. // Ensure that a node can be successfully started, but only once
  64. if err := stack.Start(); err != nil {
  65. t.Fatalf("failed to start node: %v", err)
  66. }
  67. if err := stack.Start(); err != ErrNodeRunning {
  68. t.Fatalf("start failure mismatch: have %v, want %v ", err, ErrNodeRunning)
  69. }
  70. // Ensure that a node can be stopped, but only once
  71. if err := stack.Close(); err != nil {
  72. t.Fatalf("failed to stop node: %v", err)
  73. }
  74. if err := stack.Close(); err != ErrNodeStopped {
  75. t.Fatalf("stop failure mismatch: have %v, want %v ", err, ErrNodeStopped)
  76. }
  77. }
  78. // Tests that if the data dir is already in use, an appropriate error is returned.
  79. func TestNodeUsedDataDir(t *testing.T) {
  80. // Create a temporary folder to use as the data directory
  81. dir, err := ioutil.TempDir("", "")
  82. if err != nil {
  83. t.Fatalf("failed to create temporary data directory: %v", err)
  84. }
  85. defer os.RemoveAll(dir)
  86. // Create a new node based on the data directory
  87. original, err := New(&Config{DataDir: dir})
  88. if err != nil {
  89. t.Fatalf("failed to create original protocol stack: %v", err)
  90. }
  91. defer original.Close()
  92. if err := original.Start(); err != nil {
  93. t.Fatalf("failed to start original protocol stack: %v", err)
  94. }
  95. // Create a second node based on the same data directory and ensure failure
  96. _, err = New(&Config{DataDir: dir})
  97. if err != ErrDatadirUsed {
  98. t.Fatalf("duplicate datadir failure mismatch: have %v, want %v", err, ErrDatadirUsed)
  99. }
  100. }
  101. // Tests whether a Lifecycle can be registered.
  102. func TestLifecycleRegistry_Successful(t *testing.T) {
  103. stack, err := New(testNodeConfig())
  104. if err != nil {
  105. t.Fatalf("failed to create protocol stack: %v", err)
  106. }
  107. defer stack.Close()
  108. noop := NewNoop()
  109. stack.RegisterLifecycle(noop)
  110. if !containsLifecycle(stack.lifecycles, noop) {
  111. t.Fatalf("lifecycle was not properly registered on the node, %v", err)
  112. }
  113. }
  114. // Tests whether a service's protocols can be registered properly on the node's p2p server.
  115. func TestRegisterProtocols(t *testing.T) {
  116. stack, err := New(testNodeConfig())
  117. if err != nil {
  118. t.Fatalf("failed to create protocol stack: %v", err)
  119. }
  120. defer stack.Close()
  121. fs, err := NewFullService(stack)
  122. if err != nil {
  123. t.Fatalf("could not create full service: %v", err)
  124. }
  125. for _, protocol := range fs.Protocols() {
  126. if !containsProtocol(stack.server.Protocols, protocol) {
  127. t.Fatalf("protocol %v was not successfully registered", protocol)
  128. }
  129. }
  130. for _, api := range fs.APIs() {
  131. if !containsAPI(stack.rpcAPIs, api) {
  132. t.Fatalf("api %v was not successfully registered", api)
  133. }
  134. }
  135. }
  136. // This test checks that open databases are closed with node.
  137. func TestNodeCloseClosesDB(t *testing.T) {
  138. stack, _ := New(testNodeConfig())
  139. defer stack.Close()
  140. db, err := stack.OpenDatabase("mydb", 0, 0, "", false)
  141. if err != nil {
  142. t.Fatal("can't open DB:", err)
  143. }
  144. if err = db.Put([]byte{}, []byte{}); err != nil {
  145. t.Fatal("can't Put on open DB:", err)
  146. }
  147. stack.Close()
  148. if err = db.Put([]byte{}, []byte{}); err == nil {
  149. t.Fatal("Put succeeded after node is closed")
  150. }
  151. }
  152. // This test checks that OpenDatabase can be used from within a Lifecycle Start method.
  153. func TestNodeOpenDatabaseFromLifecycleStart(t *testing.T) {
  154. stack, _ := New(testNodeConfig())
  155. defer stack.Close()
  156. var db ethdb.Database
  157. var err error
  158. stack.RegisterLifecycle(&InstrumentedService{
  159. startHook: func() {
  160. db, err = stack.OpenDatabase("mydb", 0, 0, "", false)
  161. if err != nil {
  162. t.Fatal("can't open DB:", err)
  163. }
  164. },
  165. stopHook: func() {
  166. db.Close()
  167. },
  168. })
  169. stack.Start()
  170. stack.Close()
  171. }
  172. // This test checks that OpenDatabase can be used from within a Lifecycle Stop method.
  173. func TestNodeOpenDatabaseFromLifecycleStop(t *testing.T) {
  174. stack, _ := New(testNodeConfig())
  175. defer stack.Close()
  176. stack.RegisterLifecycle(&InstrumentedService{
  177. stopHook: func() {
  178. db, err := stack.OpenDatabase("mydb", 0, 0, "", false)
  179. if err != nil {
  180. t.Fatal("can't open DB:", err)
  181. }
  182. db.Close()
  183. },
  184. })
  185. stack.Start()
  186. stack.Close()
  187. }
  188. // Tests that registered Lifecycles get started and stopped correctly.
  189. func TestLifecycleLifeCycle(t *testing.T) {
  190. stack, _ := New(testNodeConfig())
  191. defer stack.Close()
  192. started := make(map[string]bool)
  193. stopped := make(map[string]bool)
  194. // Create a batch of instrumented services
  195. lifecycles := map[string]Lifecycle{
  196. "A": &InstrumentedService{
  197. startHook: func() { started["A"] = true },
  198. stopHook: func() { stopped["A"] = true },
  199. },
  200. "B": &InstrumentedService{
  201. startHook: func() { started["B"] = true },
  202. stopHook: func() { stopped["B"] = true },
  203. },
  204. "C": &InstrumentedService{
  205. startHook: func() { started["C"] = true },
  206. stopHook: func() { stopped["C"] = true },
  207. },
  208. }
  209. // register lifecycles on node
  210. for _, lifecycle := range lifecycles {
  211. stack.RegisterLifecycle(lifecycle)
  212. }
  213. // Start the node and check that all services are running
  214. if err := stack.Start(); err != nil {
  215. t.Fatalf("failed to start protocol stack: %v", err)
  216. }
  217. for id := range lifecycles {
  218. if !started[id] {
  219. t.Fatalf("service %s: freshly started service not running", id)
  220. }
  221. if stopped[id] {
  222. t.Fatalf("service %s: freshly started service already stopped", id)
  223. }
  224. }
  225. // Stop the node and check that all services have been stopped
  226. if err := stack.Close(); err != nil {
  227. t.Fatalf("failed to stop protocol stack: %v", err)
  228. }
  229. for id := range lifecycles {
  230. if !stopped[id] {
  231. t.Fatalf("service %s: freshly terminated service still running", id)
  232. }
  233. }
  234. }
  235. // Tests that if a Lifecycle fails to start, all others started before it will be
  236. // shut down.
  237. func TestLifecycleStartupError(t *testing.T) {
  238. stack, err := New(testNodeConfig())
  239. if err != nil {
  240. t.Fatalf("failed to create protocol stack: %v", err)
  241. }
  242. defer stack.Close()
  243. started := make(map[string]bool)
  244. stopped := make(map[string]bool)
  245. // Create a batch of instrumented services
  246. lifecycles := map[string]Lifecycle{
  247. "A": &InstrumentedService{
  248. startHook: func() { started["A"] = true },
  249. stopHook: func() { stopped["A"] = true },
  250. },
  251. "B": &InstrumentedService{
  252. startHook: func() { started["B"] = true },
  253. stopHook: func() { stopped["B"] = true },
  254. },
  255. "C": &InstrumentedService{
  256. startHook: func() { started["C"] = true },
  257. stopHook: func() { stopped["C"] = true },
  258. },
  259. }
  260. // register lifecycles on node
  261. for _, lifecycle := range lifecycles {
  262. stack.RegisterLifecycle(lifecycle)
  263. }
  264. // Register a service that fails to construct itself
  265. failure := errors.New("fail")
  266. failer := &InstrumentedService{start: failure}
  267. stack.RegisterLifecycle(failer)
  268. // Start the protocol stack and ensure all started services stop
  269. if err := stack.Start(); err != failure {
  270. t.Fatalf("stack startup failure mismatch: have %v, want %v", err, failure)
  271. }
  272. for id := range lifecycles {
  273. if started[id] && !stopped[id] {
  274. t.Fatalf("service %s: started but not stopped", id)
  275. }
  276. delete(started, id)
  277. delete(stopped, id)
  278. }
  279. }
  280. // Tests that even if a registered Lifecycle fails to shut down cleanly, it does
  281. // not influence the rest of the shutdown invocations.
  282. func TestLifecycleTerminationGuarantee(t *testing.T) {
  283. stack, err := New(testNodeConfig())
  284. if err != nil {
  285. t.Fatalf("failed to create protocol stack: %v", err)
  286. }
  287. defer stack.Close()
  288. started := make(map[string]bool)
  289. stopped := make(map[string]bool)
  290. // Create a batch of instrumented services
  291. lifecycles := map[string]Lifecycle{
  292. "A": &InstrumentedService{
  293. startHook: func() { started["A"] = true },
  294. stopHook: func() { stopped["A"] = true },
  295. },
  296. "B": &InstrumentedService{
  297. startHook: func() { started["B"] = true },
  298. stopHook: func() { stopped["B"] = true },
  299. },
  300. "C": &InstrumentedService{
  301. startHook: func() { started["C"] = true },
  302. stopHook: func() { stopped["C"] = true },
  303. },
  304. }
  305. // register lifecycles on node
  306. for _, lifecycle := range lifecycles {
  307. stack.RegisterLifecycle(lifecycle)
  308. }
  309. // Register a service that fails to shot down cleanly
  310. failure := errors.New("fail")
  311. failer := &InstrumentedService{stop: failure}
  312. stack.RegisterLifecycle(failer)
  313. // Start the protocol stack, and ensure that a failing shut down terminates all
  314. // Start the stack and make sure all is online
  315. if err := stack.Start(); err != nil {
  316. t.Fatalf("failed to start protocol stack: %v", err)
  317. }
  318. for id := range lifecycles {
  319. if !started[id] {
  320. t.Fatalf("service %s: service not running", id)
  321. }
  322. if stopped[id] {
  323. t.Fatalf("service %s: service already stopped", id)
  324. }
  325. }
  326. // Stop the stack, verify failure and check all terminations
  327. err = stack.Close()
  328. if err, ok := err.(*StopError); !ok {
  329. t.Fatalf("termination failure mismatch: have %v, want StopError", err)
  330. } else {
  331. failer := reflect.TypeOf(&InstrumentedService{})
  332. if err.Services[failer] != failure {
  333. t.Fatalf("failer termination failure mismatch: have %v, want %v", err.Services[failer], failure)
  334. }
  335. if len(err.Services) != 1 {
  336. t.Fatalf("failure count mismatch: have %d, want %d", len(err.Services), 1)
  337. }
  338. }
  339. for id := range lifecycles {
  340. if !stopped[id] {
  341. t.Fatalf("service %s: service not terminated", id)
  342. }
  343. delete(started, id)
  344. delete(stopped, id)
  345. }
  346. stack.server = &p2p.Server{}
  347. stack.server.PrivateKey = testNodeKey
  348. }
  349. // Tests whether a handler can be successfully mounted on the canonical HTTP server
  350. // on the given prefix
  351. func TestRegisterHandler_Successful(t *testing.T) {
  352. node := createNode(t, 7878, 7979)
  353. // create and mount handler
  354. handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  355. w.Write([]byte("success"))
  356. })
  357. node.RegisterHandler("test", "/test", handler)
  358. // start node
  359. if err := node.Start(); err != nil {
  360. t.Fatalf("could not start node: %v", err)
  361. }
  362. // create HTTP request
  363. httpReq, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:7878/test", nil)
  364. if err != nil {
  365. t.Error("could not issue new http request ", err)
  366. }
  367. // check response
  368. resp := doHTTPRequest(t, httpReq)
  369. buf := make([]byte, 7)
  370. _, err = io.ReadFull(resp.Body, buf)
  371. if err != nil {
  372. t.Fatalf("could not read response: %v", err)
  373. }
  374. assert.Equal(t, "success", string(buf))
  375. }
  376. // Tests that the given handler will not be successfully mounted since no HTTP server
  377. // is enabled for RPC
  378. func TestRegisterHandler_Unsuccessful(t *testing.T) {
  379. node, err := New(&DefaultConfig)
  380. if err != nil {
  381. t.Fatalf("could not create new node: %v", err)
  382. }
  383. // create and mount handler
  384. handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  385. w.Write([]byte("success"))
  386. })
  387. node.RegisterHandler("test", "/test", handler)
  388. }
  389. // Tests whether websocket requests can be handled on the same port as a regular http server.
  390. func TestWebsocketHTTPOnSamePort_WebsocketRequest(t *testing.T) {
  391. node := startHTTP(t, 0, 0)
  392. defer node.Close()
  393. ws := strings.Replace(node.HTTPEndpoint(), "http://", "ws://", 1)
  394. if node.WSEndpoint() != ws {
  395. t.Fatalf("endpoints should be the same")
  396. }
  397. if !checkRPC(ws) {
  398. t.Fatalf("ws request failed")
  399. }
  400. if !checkRPC(node.HTTPEndpoint()) {
  401. t.Fatalf("http request failed")
  402. }
  403. }
  404. func TestWebsocketHTTPOnSeparatePort_WSRequest(t *testing.T) {
  405. // try and get a free port
  406. listener, err := net.Listen("tcp", "127.0.0.1:0")
  407. if err != nil {
  408. t.Fatal("can't listen:", err)
  409. }
  410. port := listener.Addr().(*net.TCPAddr).Port
  411. listener.Close()
  412. node := startHTTP(t, 0, port)
  413. defer node.Close()
  414. wsOnHTTP := strings.Replace(node.HTTPEndpoint(), "http://", "ws://", 1)
  415. ws := fmt.Sprintf("ws://127.0.0.1:%d", port)
  416. if node.WSEndpoint() == wsOnHTTP {
  417. t.Fatalf("endpoints should not be the same")
  418. }
  419. // ensure ws endpoint matches the expected endpoint
  420. if node.WSEndpoint() != ws {
  421. t.Fatalf("ws endpoint is incorrect: expected %s, got %s", ws, node.WSEndpoint())
  422. }
  423. if !checkRPC(ws) {
  424. t.Fatalf("ws request failed")
  425. }
  426. if !checkRPC(node.HTTPEndpoint()) {
  427. t.Fatalf("http request failed")
  428. }
  429. }
  430. type rpcPrefixTest struct {
  431. httpPrefix, wsPrefix string
  432. // These lists paths on which JSON-RPC should be served / not served.
  433. wantHTTP []string
  434. wantNoHTTP []string
  435. wantWS []string
  436. wantNoWS []string
  437. }
  438. func TestNodeRPCPrefix(t *testing.T) {
  439. t.Parallel()
  440. tests := []rpcPrefixTest{
  441. // both off
  442. {
  443. httpPrefix: "", wsPrefix: "",
  444. wantHTTP: []string{"/", "/?p=1"},
  445. wantNoHTTP: []string{"/test", "/test?p=1"},
  446. wantWS: []string{"/", "/?p=1"},
  447. wantNoWS: []string{"/test", "/test?p=1"},
  448. },
  449. // only http prefix
  450. {
  451. httpPrefix: "/testprefix", wsPrefix: "",
  452. wantHTTP: []string{"/testprefix", "/testprefix?p=1", "/testprefix/x", "/testprefix/x?p=1"},
  453. wantNoHTTP: []string{"/", "/?p=1", "/test", "/test?p=1"},
  454. wantWS: []string{"/", "/?p=1"},
  455. wantNoWS: []string{"/testprefix", "/testprefix?p=1", "/test", "/test?p=1"},
  456. },
  457. // only ws prefix
  458. {
  459. httpPrefix: "", wsPrefix: "/testprefix",
  460. wantHTTP: []string{"/", "/?p=1"},
  461. wantNoHTTP: []string{"/testprefix", "/testprefix?p=1", "/test", "/test?p=1"},
  462. wantWS: []string{"/testprefix", "/testprefix?p=1", "/testprefix/x", "/testprefix/x?p=1"},
  463. wantNoWS: []string{"/", "/?p=1", "/test", "/test?p=1"},
  464. },
  465. // both set
  466. {
  467. httpPrefix: "/testprefix", wsPrefix: "/testprefix",
  468. wantHTTP: []string{"/testprefix", "/testprefix?p=1", "/testprefix/x", "/testprefix/x?p=1"},
  469. wantNoHTTP: []string{"/", "/?p=1", "/test", "/test?p=1"},
  470. wantWS: []string{"/testprefix", "/testprefix?p=1", "/testprefix/x", "/testprefix/x?p=1"},
  471. wantNoWS: []string{"/", "/?p=1", "/test", "/test?p=1"},
  472. },
  473. }
  474. for _, test := range tests {
  475. test := test
  476. name := fmt.Sprintf("http=%s ws=%s", test.httpPrefix, test.wsPrefix)
  477. t.Run(name, func(t *testing.T) {
  478. cfg := &Config{
  479. HTTPHost: "127.0.0.1",
  480. HTTPPathPrefix: test.httpPrefix,
  481. WSHost: "127.0.0.1",
  482. WSPathPrefix: test.wsPrefix,
  483. }
  484. node, err := New(cfg)
  485. if err != nil {
  486. t.Fatal("can't create node:", err)
  487. }
  488. defer node.Close()
  489. if err := node.Start(); err != nil {
  490. t.Fatal("can't start node:", err)
  491. }
  492. test.check(t, node)
  493. })
  494. }
  495. }
  496. func (test rpcPrefixTest) check(t *testing.T, node *Node) {
  497. t.Helper()
  498. httpBase := "http://" + node.http.listenAddr()
  499. wsBase := "ws://" + node.http.listenAddr()
  500. if node.WSEndpoint() != wsBase+test.wsPrefix {
  501. t.Errorf("Error: node has wrong WSEndpoint %q", node.WSEndpoint())
  502. }
  503. for _, path := range test.wantHTTP {
  504. resp := rpcRequest(t, httpBase+path)
  505. if resp.StatusCode != 200 {
  506. t.Errorf("Error: %s: bad status code %d, want 200", path, resp.StatusCode)
  507. }
  508. }
  509. for _, path := range test.wantNoHTTP {
  510. resp := rpcRequest(t, httpBase+path)
  511. if resp.StatusCode != 404 {
  512. t.Errorf("Error: %s: bad status code %d, want 404", path, resp.StatusCode)
  513. }
  514. }
  515. for _, path := range test.wantWS {
  516. err := wsRequest(t, wsBase+path, "")
  517. if err != nil {
  518. t.Errorf("Error: %s: WebSocket connection failed: %v", path, err)
  519. }
  520. }
  521. for _, path := range test.wantNoWS {
  522. err := wsRequest(t, wsBase+path, "")
  523. if err == nil {
  524. t.Errorf("Error: %s: WebSocket connection succeeded for path in wantNoWS", path)
  525. }
  526. }
  527. }
  528. func createNode(t *testing.T, httpPort, wsPort int) *Node {
  529. conf := &Config{
  530. HTTPHost: "127.0.0.1",
  531. HTTPPort: httpPort,
  532. WSHost: "127.0.0.1",
  533. WSPort: wsPort,
  534. }
  535. node, err := New(conf)
  536. node.pluginManager = plugin.NewEmptyPluginManager()
  537. if err != nil {
  538. t.Fatalf("could not create a new node: %v", err)
  539. }
  540. return node
  541. }
  542. func startHTTP(t *testing.T, httpPort, wsPort int) *Node {
  543. node := createNode(t, httpPort, wsPort)
  544. err := node.Start()
  545. if err != nil {
  546. t.Fatalf("could not start http service on node: %v", err)
  547. }
  548. return node
  549. }
  550. func doHTTPRequest(t *testing.T, req *http.Request) *http.Response {
  551. client := http.DefaultClient
  552. resp, err := client.Do(req)
  553. if err != nil {
  554. t.Fatalf("could not issue a GET request to the given endpoint: %v", err)
  555. }
  556. return resp
  557. }
  558. func containsProtocol(stackProtocols []p2p.Protocol, protocol p2p.Protocol) bool {
  559. for _, a := range stackProtocols {
  560. if reflect.DeepEqual(a, protocol) {
  561. return true
  562. }
  563. }
  564. return false
  565. }
  566. func containsAPI(stackAPIs []rpc.API, api rpc.API) bool {
  567. for _, a := range stackAPIs {
  568. if reflect.DeepEqual(a, api) {
  569. return true
  570. }
  571. }
  572. return false
  573. }