Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit 4493ff4

Browse files
authored
Merge pull request #131 from ethereum-optimism/impl-driver
ref impl: driver agent: respond to head events and stay in sync
2 parents 03a75b5 + 94dba5a commit 4493ff4

File tree

12 files changed

+715
-3
lines changed

12 files changed

+715
-3
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/pmezard/go-difflib v1.0.0 // indirect
2929
github.com/prometheus/tsdb v0.7.1 // indirect
3030
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
31+
github.com/stretchr/objx v0.1.1 // indirect
3132
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
3233
github.com/tklauser/go-sysconf v0.3.5 // indirect
3334
github.com/tklauser/numcpus v0.2.2 // indirect

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3
336336
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
337337
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
338338
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
339+
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
339340
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
340341
github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
341342
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

opnode/internal/testlog/LICENSE

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
GNU LESSER GENERAL PUBLIC LICENSE
2+
Version 3, 29 June 2007
3+
4+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5+
Everyone is permitted to copy and distribute verbatim copies
6+
of this license document, but changing it is not allowed.
7+
8+
9+
This version of the GNU Lesser General Public License incorporates
10+
the terms and conditions of version 3 of the GNU General Public
11+
License, supplemented by the additional permissions listed below.
12+
13+
0. Additional Definitions.
14+
15+
As used herein, "this License" refers to version 3 of the GNU Lesser
16+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
17+
General Public License.
18+
19+
"The Library" refers to a covered work governed by this License,
20+
other than an Application or a Combined Work as defined below.
21+
22+
An "Application" is any work that makes use of an interface provided
23+
by the Library, but which is not otherwise based on the Library.
24+
Defining a subclass of a class defined by the Library is deemed a mode
25+
of using an interface provided by the Library.
26+
27+
A "Combined Work" is a work produced by combining or linking an
28+
Application with the Library. The particular version of the Library
29+
with which the Combined Work was made is also called the "Linked
30+
Version".
31+
32+
The "Minimal Corresponding Source" for a Combined Work means the
33+
Corresponding Source for the Combined Work, excluding any source code
34+
for portions of the Combined Work that, considered in isolation, are
35+
based on the Application, and not on the Linked Version.
36+
37+
The "Corresponding Application Code" for a Combined Work means the
38+
object code and/or source code for the Application, including any data
39+
and utility programs needed for reproducing the Combined Work from the
40+
Application, but excluding the System Libraries of the Combined Work.
41+
42+
1. Exception to Section 3 of the GNU GPL.
43+
44+
You may convey a covered work under sections 3 and 4 of this License
45+
without being bound by section 3 of the GNU GPL.
46+
47+
2. Conveying Modified Versions.
48+
49+
If you modify a copy of the Library, and, in your modifications, a
50+
facility refers to a function or data to be supplied by an Application
51+
that uses the facility (other than as an argument passed when the
52+
facility is invoked), then you may convey a copy of the modified
53+
version:
54+
55+
a) under this License, provided that you make a good faith effort to
56+
ensure that, in the event an Application does not supply the
57+
function or data, the facility still operates, and performs
58+
whatever part of its purpose remains meaningful, or
59+
60+
b) under the GNU GPL, with none of the additional permissions of
61+
this License applicable to that copy.
62+
63+
3. Object Code Incorporating Material from Library Header Files.
64+
65+
The object code form of an Application may incorporate material from
66+
a header file that is part of the Library. You may convey such object
67+
code under terms of your choice, provided that, if the incorporated
68+
material is not limited to numerical parameters, data structure
69+
layouts and accessors, or small macros, inline functions and templates
70+
(ten or fewer lines in length), you do both of the following:
71+
72+
a) Give prominent notice with each copy of the object code that the
73+
Library is used in it and that the Library and its use are
74+
covered by this License.
75+
76+
b) Accompany the object code with a copy of the GNU GPL and this license
77+
document.
78+
79+
4. Combined Works.
80+
81+
You may convey a Combined Work under terms of your choice that,
82+
taken together, effectively do not restrict modification of the
83+
portions of the Library contained in the Combined Work and reverse
84+
engineering for debugging such modifications, if you also do each of
85+
the following:
86+
87+
a) Give prominent notice with each copy of the Combined Work that
88+
the Library is used in it and that the Library and its use are
89+
covered by this License.
90+
91+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
92+
document.
93+
94+
c) For a Combined Work that displays copyright notices during
95+
execution, include the copyright notice for the Library among
96+
these notices, as well as a reference directing the user to the
97+
copies of the GNU GPL and this license document.
98+
99+
d) Do one of the following:
100+
101+
0) Convey the Minimal Corresponding Source under the terms of this
102+
License, and the Corresponding Application Code in a form
103+
suitable for, and under terms that permit, the user to
104+
recombine or relink the Application with a modified version of
105+
the Linked Version to produce a modified Combined Work, in the
106+
manner specified by section 6 of the GNU GPL for conveying
107+
Corresponding Source.
108+
109+
1) Use a suitable shared library mechanism for linking with the
110+
Library. A suitable mechanism is one that (a) uses at run time
111+
a copy of the Library already present on the user's computer
112+
system, and (b) will operate properly with a modified version
113+
of the Library that is interface-compatible with the Linked
114+
Version.
115+
116+
e) Provide Installation Information, but only if you would otherwise
117+
be required to provide such information under section 6 of the
118+
GNU GPL, and only to the extent that such information is
119+
necessary to install and execute a modified version of the
120+
Combined Work produced by recombining or relinking the
121+
Application with a modified version of the Linked Version. (If
122+
you use option 4d0, the Installation Information must accompany
123+
the Minimal Corresponding Source and Corresponding Application
124+
Code. If you use option 4d1, you must provide the Installation
125+
Information in the manner specified by section 6 of the GNU GPL
126+
for conveying Corresponding Source.)
127+
128+
5. Combined Libraries.
129+
130+
You may place library facilities that are a work based on the
131+
Library side by side in a single library together with other library
132+
facilities that are not Applications and are not covered by this
133+
License, and convey such a combined library under terms of your
134+
choice, if you do both of the following:
135+
136+
a) Accompany the combined library with a copy of the same work based
137+
on the Library, uncombined with any other library facilities,
138+
conveyed under the terms of this License.
139+
140+
b) Give prominent notice with the combined library that part of it
141+
is a work based on the Library, and explaining where to find the
142+
accompanying uncombined form of the same work.
143+
144+
6. Revised Versions of the GNU Lesser General Public License.
145+
146+
The Free Software Foundation may publish revised and/or new versions
147+
of the GNU Lesser General Public License from time to time. Such new
148+
versions will be similar in spirit to the present version, but may
149+
differ in detail to address new problems or concerns.
150+
151+
Each version is given a distinguishing version number. If the
152+
Library as you received it specifies that a certain numbered version
153+
of the GNU Lesser General Public License "or any later version"
154+
applies to it, you have the option of following the terms and
155+
conditions either of that published version or of any later version
156+
published by the Free Software Foundation. If the Library as you
157+
received it does not specify a version number of the GNU Lesser
158+
General Public License, you may choose any version of the GNU Lesser
159+
General Public License ever published by the Free Software Foundation.
160+
161+
If the Library as you received it specifies that a proxy can decide
162+
whether future versions of the GNU Lesser General Public License shall
163+
apply, that proxy's public statement of acceptance of any version is
164+
permanent authorization for you to choose that version for the
165+
Library.

opnode/internal/testlog/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# testlog
2+
3+
`github.com/ethereum/go-ethereum/internal/testlog`: a Go-ethereum util for logging in tests.
4+
5+
Since we use the same logging, but as an external package, we have to move the test utility to our own internal package.
6+

opnode/internal/testlog/testlog.go

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright 2019 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+
17+
// Package testlog provides a log handler for unit tests.
18+
package testlog
19+
20+
import (
21+
"sync"
22+
"testing"
23+
24+
"github.com/ethereum/go-ethereum/log"
25+
)
26+
27+
// Handler returns a log handler which logs to the unit test log of t.
28+
func Handler(t *testing.T, level log.Lvl) log.Handler {
29+
return log.LvlFilterHandler(level, &handler{t, log.TerminalFormat(false)})
30+
}
31+
32+
type handler struct {
33+
t *testing.T
34+
fmt log.Format
35+
}
36+
37+
func (h *handler) Log(r *log.Record) error {
38+
h.t.Logf("%s", h.fmt.Format(r))
39+
return nil
40+
}
41+
42+
// logger implements log.Logger such that all output goes to the unit test log via
43+
// t.Logf(). All methods in between logger.Trace, logger.Debug, etc. are marked as test
44+
// helpers, so the file and line number in unit test output correspond to the call site
45+
// which emitted the log message.
46+
type logger struct {
47+
t *testing.T
48+
l log.Logger
49+
mu *sync.Mutex
50+
h *bufHandler
51+
}
52+
53+
type bufHandler struct {
54+
buf []*log.Record
55+
fmt log.Format
56+
}
57+
58+
func (h *bufHandler) Log(r *log.Record) error {
59+
h.buf = append(h.buf, r)
60+
return nil
61+
}
62+
63+
// Logger returns a logger which logs to the unit test log of t.
64+
func Logger(t *testing.T, level log.Lvl) log.Logger {
65+
l := &logger{
66+
t: t,
67+
l: log.New(),
68+
mu: new(sync.Mutex),
69+
h: &bufHandler{fmt: log.TerminalFormat(false)},
70+
}
71+
l.l.SetHandler(log.LvlFilterHandler(level, l.h))
72+
return l
73+
}
74+
75+
func (l *logger) Trace(msg string, ctx ...interface{}) {
76+
l.t.Helper()
77+
l.mu.Lock()
78+
defer l.mu.Unlock()
79+
l.l.Trace(msg, ctx...)
80+
l.flush()
81+
}
82+
83+
func (l *logger) Debug(msg string, ctx ...interface{}) {
84+
l.t.Helper()
85+
l.mu.Lock()
86+
defer l.mu.Unlock()
87+
l.l.Debug(msg, ctx...)
88+
l.flush()
89+
}
90+
91+
func (l *logger) Info(msg string, ctx ...interface{}) {
92+
l.t.Helper()
93+
l.mu.Lock()
94+
defer l.mu.Unlock()
95+
l.l.Info(msg, ctx...)
96+
l.flush()
97+
}
98+
99+
func (l *logger) Warn(msg string, ctx ...interface{}) {
100+
l.t.Helper()
101+
l.mu.Lock()
102+
defer l.mu.Unlock()
103+
l.l.Warn(msg, ctx...)
104+
l.flush()
105+
}
106+
107+
func (l *logger) Error(msg string, ctx ...interface{}) {
108+
l.t.Helper()
109+
l.mu.Lock()
110+
defer l.mu.Unlock()
111+
l.l.Error(msg, ctx...)
112+
l.flush()
113+
}
114+
115+
func (l *logger) Crit(msg string, ctx ...interface{}) {
116+
l.t.Helper()
117+
l.mu.Lock()
118+
defer l.mu.Unlock()
119+
l.l.Crit(msg, ctx...)
120+
l.flush()
121+
}
122+
123+
func (l *logger) New(ctx ...interface{}) log.Logger {
124+
return &logger{l.t, l.l.New(ctx...), l.mu, l.h}
125+
}
126+
127+
func (l *logger) GetHandler() log.Handler {
128+
return l.l.GetHandler()
129+
}
130+
131+
func (l *logger) SetHandler(h log.Handler) {
132+
l.l.SetHandler(h)
133+
}
134+
135+
// flush writes all buffered messages and clears the buffer.
136+
func (l *logger) flush() {
137+
l.t.Helper()
138+
for _, r := range l.h.buf {
139+
l.t.Logf("%s", l.h.fmt.Format(r))
140+
}
141+
l.h.buf = nil
142+
}

0 commit comments

Comments
 (0)