test/test_protocol: add checksync command to assert nodes are in sync.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-05-17 13:48:11 +09:30
parent 7f90d183da
commit 056c219bc1
7 changed files with 27 additions and 0 deletions

View File

@ -7,6 +7,7 @@ A:recvrevoke
B:commit B:commit
A:recvcommit A:recvcommit
B:recvrevoke B:recvrevoke
checksync
echo ***A*** echo ***A***
A:dump A:dump
echo ***B*** echo ***B***

View File

@ -9,6 +9,7 @@ A:recvrevoke
B:commit B:commit
A:recvcommit A:recvcommit
B:recvrevoke B:recvrevoke
checksync
echo ***A*** echo ***A***
A:dump A:dump
echo ***B*** echo ***B***

View File

@ -17,6 +17,7 @@ A:commit
B:recvcommit B:recvcommit
A:recvrevoke A:recvrevoke
checksync
echo ***A*** echo ***A***
A:dump A:dump
echo ***B*** echo ***B***

View File

@ -14,6 +14,7 @@ A:recvrevoke
B:commit B:commit
A:recvcommit A:recvcommit
B:recvrevoke B:recvrevoke
checksync
echo ***A*** echo ***A***
A:dump A:dump
echo ***B*** echo ***B***

View File

@ -12,6 +12,7 @@ A:recvrevoke
B:commit B:commit
A:recvcommit A:recvcommit
B:recvrevoke B:recvrevoke
checksync
echo ***A*** echo ***A***
A:dump A:dump
echo ***B*** echo ***B***

View File

@ -15,6 +15,7 @@ A:commit
B:recvcommit B:recvcommit
A:recvrevoke A:recvrevoke
checksync
echo ***A*** echo ***A***
A:dump A:dump
echo ***B*** echo ***B***

View File

@ -449,6 +449,12 @@ static void do_cmd(struct peer *peer)
read_peer(peer, "C", cmd); read_peer(peer, "C", cmd);
read_in(peer->infd, &sig, sizeof(sig)); read_in(peer->infd, &sig, sizeof(sig));
receive_commit(peer, &sig); receive_commit(peer, &sig);
} else if (streq(cmd, "checksync")) {
write_all(peer->cmddonefd, &peer->us->funding,
sizeof(peer->us->funding));
write_all(peer->cmddonefd, &peer->them->funding,
sizeof(peer->them->funding));
return;
} else if (streq(cmd, "dump")) { } else if (streq(cmd, "dump")) {
dump_peer(peer, false); dump_peer(peer, false);
} else if (streq(cmd, "dumpall")) { } else if (streq(cmd, "dumpall")) {
@ -545,6 +551,21 @@ int main(int argc, char *argv[])
printf("%s\n", cmd + 5); printf("%s\n", cmd + 5);
fflush(stdout); fflush(stdout);
continue; continue;
} else if (streq(cmd, "checksync")) {
struct funding fa_us, fa_them, fb_us, fb_them;
if (!write_all(acmd[1], cmd, strlen(cmd)+1)
|| !write_all(bcmd[1], cmd, strlen(cmd)+1))
errx(1, "Failed writing command to peers");
alarm(5);
if (!read_all(adonefd[0], &fa_us, sizeof(fa_us))
|| !read_all(adonefd[0], &fa_them, sizeof(fa_them))
|| !read_all(bdonefd[0], &fb_us, sizeof(fb_us))
|| !read_all(bdonefd[0], &fb_them, sizeof(fb_them)))
errx(1, "Failed reading status from peers");
if (!structeq(&fa_us, &fb_them)
|| !structeq(&fa_them, &fb_us))
errx(1, "checksync: not equal");
continue;
} else if (strstarts(cmd, "#") || streq(cmd, "")) } else if (strstarts(cmd, "#") || streq(cmd, ""))
continue; continue;
else else